Search code examples
c#multithreadingasp.net-mvc-3entity-frameworkvisual-studio-debugging

Visual Studio 2012 MVC 3 multiple unwanted threads


I have an MVC 3 C# project that I created and have been using in Visual Studio 2012. I am also using the entity framework. When debugging, I get the known "The process or thread has changed since last step." message on the debugging icon. For some time, it didn't change the behavior of the program so I ignored it.

Recently, however, I have had the same message and behavior (with the debugger jumping back to the beginning of the executed method where my breakpoint is) except that now my code is actually getting executed twice. What I mean is that now any database inserts are being run at least twice. It may be helpful to know I am also using the entity framework, and my inserts are all being done by importing a stored procedure that does a simple insert.

Nowhere in my code do I explicitly spin up new threads or attempt to do any multi-threading. I am not very familiar with multi-threading, but when I debug and use the threads window, I see one main thread with 7 threads, and two Worker Threads. (Sorry I would post an image but I'm a new user and they won't let me).

Then, when I hit F5 to continue, my single breakpoint is hit again, I see one main thread, 3 threads, and 6!! Worker Threads.

Where can I look to see where / why there are multiple threads being spun up? Also, what could I have done to get the process changed since last step message? I have researched this for weeks with no solution.

Thank you in advance for any help!


Solution

  • So I figured out what the problem was. The issue of things being saved to the database twice was a result of having unobtrusive ajax on the page twice (once in my layout page, and one on the individual pages).

    The issue of seeing multiple threads seems to be something with browsers since I am not doing any threading of any kind in my application. Although the little icon and stepping back in the method is annoying (and I'd like to resolve it at some point), it does not actually alter the behavior of the application.