Visual Studio: ContextSwitchDeadlock
The ContextSwitchDeadlock
doesn't necessarily mean your code has an issue, just that there is a potential. If you go to Debug > Exceptions
in the menu and expand the Managed Debugging Assistants
, you will find ContextSwitchDeadlock
is enabled.
If you disable this, VS will no longer warn you when items are taking a long time to process. In some cases you may validly have a long-running operation. It's also helpful if you are debugging and have stopped on a line while this is processing - you don't want it to complain before you've had a chance to dig into an issue.
In Visual Studio 2017, unchecked the ContextSwitchDeadlock option by:
Debug > Windows > Exception Settings
In Exception Setting Windows: Uncheck the ContextSwitchDeadlock option
As Pedro said, you have an issue with the debugger preventing the message pump if you are stepping through code.
But if you are performing a long running operation on the UI thread, then call Application.DoEvents() which explicitly pumps the message queue and then returns control to your current method.
However if you are doing this I would recommend at looking at your design so that you can perform processing off the UI thread so that your UI remains nice and snappy.