开发者

Breakpoint not hit and code not executed?

I'm facing an issue which I can't seem to wrap my head around.

private void IndexEntityType(Type targetType, bool onlyNew)
{
    Logger.Debug("generating index for {0}", targetType);

    using (var wrapper = SessionWrapper.For(targetType, true))
    {
        var session = wrapper.Session;
        session.FlushMode = FlushMode.Never;
        session.CacheMode = CacheMode.Ignore;

        var entities = GetEntities(targetType, onlyNew, session);
        Logger.Debug("Indexing {0} entities", entities.Count);

        // Create a Full Text session.
        using (var fullTextSession = Search.CreateFullTextSession(session))
        using (var transaction = fullTextSession.BeginTransaction())
        {
            fullTextSession.CacheMode = CacheMode.Ignore;

            foreach (var entity in entities)
            {
               fullTextSession.Index(entity);
            }

            try
            {
                transaction.Commit();
            }
            catch (Exception ex)
            {
                Logger.Error("could not commit fulltext session transaction", ex);
            }
        }

        Logger.Debug("generated index for {0}", targetType);
    }

    ReQueueTimers(onlyNew);
}

I'm trying to debug this and have set breakpoints at the first row (Logger.Debug) and the last row (ReQueueTimers).

However, when stepping through the code, the last call (ReQueueTimers(onlyNew)) is never invoked, nor 开发者_如何学JAVAhitting the breakpoint. How can that be? Does the compiler "remove it when optimizing" somehow?

Does anyone have any hint on what might trigger this behavior?

EDIT: This is run in multiple threads if that might have anything to do with it.


It could be that your code is throwing an exception - if anything other than the transaction.Commit() throws an exception, the ReQueueTimers call won't be made. You could prove this by getting Visual Studio to break on all CLR exceptions - in the Debug menu, select "Exceptions", and check the "Thrown" box on the "Common Language Runtime Exceptions" row. Then start debugging again.

On the other hand, I have sometimes had Visual Studio just give up stepping through code halfway through debugging a method. Maybe this is the cause - it might have something to do with multiple threads. If you remove the first breakpoint and leave the one on the ReQueueTimers call, does this make any difference?


As a little addition to what Graham said:

If you run on multiple threads and an exception is thrown on that thread and is not caught, the thread is aborted.


I had the very same issue from 2 days and banged my head dead until... I found this somewhere on the net:

Make sure that your target code actually builds when you build your solution/project. To do that, go to Build->Configuration Manager and make sure the corresponding project is checked (In the rightmost column).

Mind you, for some misterious reason that only Gates knows, the box was unchecked!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜