harriyott.com

Wednesday, May 17, 2006

ContextSwitchDeadlock was detected when debugging in Visual Studio 2005

I've been having issues with a "ContextSwitchDeadlock was detected" error message popping up when debugging. The message text is a baffling

The CLR has been unable to transition from COM context 0x197060 to COM context 0x196ef0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

I've read a few things about a config file, but I couldn't get this to work reliably. Instead, you can switch the MDA off by going to:

Debug -> Exceptions -> Managed Debug Assistants

and unchecking the ContextSwitchDeadlock item. Thanks to Scott Munro.

[Tags: ]

51 Comments:

Anonymous Anonymous said...

Hey thanks for the tip! I'm new to the .net world (from VC++/MFC) and this is one of the first annoyances to hit me. I'm sure there will be more.

This is I suppose a condition worthy of flagging but not while debugging :)

June 29, 2006 6:05 PM  
Anonymous Anonymous said...

I also ran into an issue with the FileOpenDialog. Seems there are security settings and while I could set some of the properties and actually show the dialog trying to access the FileName property would throw an error.

Solution:
Project->Properties->Security

and check the 'Enable ClickOnce Security Settings'

June 29, 2006 6:09 PM  
Anonymous Simon said...

Hey, thanks for the comment. I'm glad you found it useful. I posted it in hope that someone would. I used to be a VC++/MFC developer too, and there is a lot to learn. It's really only the syntax that's the same; the .NET framework is totally different to MFC.

June 30, 2006 7:24 PM  
Anonymous Anonymous said...

Hi Simon
you're just great! It worked!
Thank you, Peter

July 26, 2006 1:06 PM  
Anonymous Simon said...

Thankyou Peter, glad you liked it. To be fair, I probably wouldn't have posted it if it didn't work ;-)

July 28, 2006 12:49 PM  
Anonymous Anonymous said...

That Work Thanks a million!!!
George

September 08, 2006 8:52 AM  
Anonymous Anonymous said...

Hi Simon

Thanks a lot! I kiss your feet ....

Greets
Benni

September 14, 2006 8:37 AM  
Anonymous Simon said...

Ha, thanks Benni!

September 14, 2006 8:41 AM  
Anonymous Anonymous said...

Grazie 1000 (thanks a lot)
daniele

September 27, 2006 6:45 AM  
Blogger Mohan said...

Hi Simon,

While i appreciate the fact that turning this off will allow us to continue to debug, i am worried whether there is actually some deadlock occuring while calling COM interops (like MS Word interop components)... and will result in app crashing at a later time..

Just thinking..

Cheers
Mohan

October 11, 2006 4:15 PM  
Anonymous Simon said...

Good point Mohan. I've not done anything with COM interops, so it's not an issue for me yet. You can always switch it back on again when debugging something of that nature.

October 11, 2006 8:30 PM  
Anonymous Anonymous said...

Thank you sooooo much!! This was driving me NUTS trying to debug my programs in 60 seconds or less. My next question is WHY do they tell you to create a application.mda.config file that it just ignores anyway?! It's SO much easier to just go to a menu and click a checkbox!! (pant pant) Ok, I'm done. Thanks again.
- John

October 12, 2006 4:50 PM  
Anonymous Anonymous said...

Thanks alot........... it was soooo very helpful..............

Thanks Thanks Thanks Thanks

October 17, 2006 12:46 PM  
Anonymous Nitin said...

Thanks a Ton!! Really Eased the Pain.

October 27, 2006 2:25 PM  
Anonymous Anonymous said...

Hi all,
It was helpful for me in debugging C# application.
It was really annoying.

Thanks a lot!!!!!!!!
Zevik

October 27, 2006 5:13 PM  
Anonymous Anonymous said...

Add one more grateful person to your list! Thanks! That thing drove me crazy, and MSDN was no help.

November 03, 2006 8:17 PM  
Anonymous Anonymous said...

Thanks so much. You are my hero!

November 03, 2006 10:58 PM  
Anonymous Anonymous said...

My menu doesn't have that option (Exceptions). I'm using the final release of VS 2005. I go to Debug and all I have for options are: Windows, Start Debugging, Start Without Debugging, Attach to process, Step Over, Toggle Breakpoint, Delete All breakpoints.)

Am I looking in the wrong place? Thanks!

November 08, 2006 10:10 PM  
Anonymous Simon said...

No, that should be the right place. I don't know why it doesn't show up on yours. The shortcut key on mine is Ctrl-D, E. Maybe that will work for you.

November 09, 2006 9:28 AM  
Anonymous Anonymous said...

thanks a ton 4 this shortcut

November 14, 2006 4:10 PM  
Anonymous Anonymous said...

Simply add the "Exceptions" menu-item, by choosing

Tools - Customize

Categorie "Debug", click and hold "Exceptions..." (from the commands pane), and drag it to your Debug menu.

So if you have other menu-items missing, just dollow the same routine.

Johan

November 20, 2006 10:34 AM  
Anonymous Anonymous said...

Hey gracias, me han salvado de un dolor de cabeza.

December 06, 2006 6:13 PM  
Anonymous Simon said...

Eres muy agradable. ¡Me causó absolutamente un dolor de cabeza!

December 08, 2006 5:25 PM  
Anonymous Anonymous said...

Hi guys!

I think I'm more grateful to Johan than Simon because my colleagues and I have been searching forum after forum and could not find the 'Exceptions' in our Debug menu!! So so frustrating until we read Johan's simple tip to drag it there. Thanks a million Johan!

You have just helped the government of Australia! :)

Himanshu

December 11, 2006 12:24 AM  
Anonymous Anonymous said...

If your ContextSwitchdeadLock was caused by some really heavy looping (like in my case - constructing tables out from large set of row data)you can avoid the lock by calling Application.DoEvents(); in C#. It processes the event queue and the MDA knows the application is doing fine and won't forcecrash it.

Tero Rönkkö - www.ronkko.fi

December 11, 2006 5:14 AM  
Anonymous Anonymous said...

thanks harriot.. thats a lot of help buddy...
- dexter

December 11, 2006 1:11 PM  
Blogger Preston said...

Tero's solution of calling Application.DoEvents(); works well and has the advantage of keeping the form repainting when needed while a long process runs.

February 12, 2007 10:41 PM  
Anonymous Eych said...

THANKS!!!

February 14, 2007 1:38 PM  
Anonymous Anonymous said...

Thanks a lot;

March 12, 2007 1:56 AM  
Anonymous Michiel Wiegers said...

And another Thanks! This anoying thing is a waste of time and causing me every time to startover again.

March 20, 2007 11:02 AM  
Anonymous Anonymous said...

Thank you very much. This has solved a big pain in the rear and I also learned something else helpful with the comments about Application.DoEvents.

March 27, 2007 11:54 PM  
Anonymous Rick said...

So, let me see if I get that error message right:

After COM and VisualStudio shacked up (context/apartment), COM wouldn't put out (non pumping), spent all VisualStudio's $$$ (usage over time) and VisualStudio got primitive on COM's ass (negative performance impact).

I understand it completely.

March 28, 2007 3:29 PM  
Anonymous Anonymous said...

Thanks a lot man!!!

Best regards from Spain

April 03, 2007 9:29 AM  
Blogger Vlad said...

Thank you very much, you have saved my a lot of time.

April 04, 2007 3:22 PM  
Anonymous Anonymous said...

Hello to all

I am just not able to find the exception part in the menu or able to add through what JOHAN has written. Please help me as I am not able to get rid of this error and it is driving me nuts.

-Rahul Sharma

May 01, 2007 10:46 AM  
Anonymous Anonymous said...

Ctrl+Alt+E from within VS.2005 will bring up the dialog he mentioned.

May 02, 2007 2:45 PM  
Anonymous Anonymous said...

Tnx dude, finally a post worth looking @ ;)

Grtz

May 24, 2007 11:13 AM  
Anonymous Anonymous said...

You guys are the best of Visual Basic world. Thanks .....

June 14, 2007 1:39 PM  
Anonymous Anonymous said...

Thanks mate!

Its an annoying thing, so why is it by default checked?

July 18, 2007 10:47 AM  
Anonymous Anonymous said...

Hello Simon,
Thank you very much..

Best Regard,
Syira
Malaysia

July 25, 2007 4:33 AM  
Anonymous Anonymous said...

That has been driving me bonkers!

Thanks very much for this simple solution. The MS site has a complete article explaining about this (which doesn’t work). Very much appreciated.

August 16, 2007 3:46 PM  
Blogger JFalter said...

Thanks so much. This thing has been driving me nuts!

August 28, 2007 4:35 PM  
Anonymous Anonymous said...

Thanks for that....that was getting to be a pain in the but...I had to hurry up and do my debugging in 60 seconds....sucked.

September 01, 2007 8:58 PM  
Anonymous Anonymous said...

Debug --> Exceptions menu pick missing. Was I losing my sight? My mind? No, just yet another VS 2005 quirk. If you want to follow the above steps, but your Debug | Exceptions menu pick is missing, as mine was, display it with Ctrl + Alt + E or go to this handy post to get it back: http://blogs.vertigo.com/personal/KeithC/Blog/Lists/Posts/Post.aspx?ID=16

September 13, 2007 3:25 PM  
Blogger Bobby said...

i also got this problem -----
The CLR has been unable to transition from COM context 0x1c3008 to COM context 0x1c3178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

i had done all the things, including

this,
Debug -> Exceptions -> Managed Debug Assistants
and unchecking the ContextSwitchDeadlock item.

and also this in config file



contextSwitchDeadlock enable="false"



but problem is not going to solve.
can any one suggest me ????
i am waiting for ur (all of programmer)reply

October 08, 2007 9:00 AM  
Anonymous Anonymous said...

Thanks for the info about disabling the MDA notification. Also, tip on using Application.DoEvents() was very helpful

February 13, 2008 10:02 AM  
Anonymous Anonymous said...

la verdad no me funciono nada, lo unicco que consegui, es que la memoria se disparara hasta los 2.5 Gb en RAM, saludos, espero encontrar una solucion

April 28, 2008 2:02 AM  
Anonymous Anonymous said...

Thank soooo much

May 15, 2008 4:39 PM  
Anonymous Anonymous said...

Hey guy,
Just disabling the messgae is not solution for this issue. My application keep on wiating ta same place and its not returning the control to execute next statement.
What could be the problem
Thanks,

July 01, 2008 3:34 PM  
Anonymous Anonymous said...

49 CommentsClose this window Jump to comment form
Anonymous said...
Hey thanks for the tip! I'm new to the .net world (from VC++/MFC) and this is one of the first annoyances to hit me. I'm sure there will be more.

This is I suppose a condition worthy of flagging but not while debugging :)

June 29, 2006 6:05 PM


Anonymous said...
I also ran into an issue with the FileOpenDialog. Seems there are security settings and while I could set some of the properties and actually show the dialog trying to access the FileName property would throw an error.

Solution:
Project->Properties->Security

and check the 'Enable ClickOnce Security Settings'

June 29, 2006 6:09 PM


Simon said...
Hey, thanks for the comment. I'm glad you found it useful. I posted it in hope that someone would. I used to be a VC++/MFC developer too, and there is a lot to learn. It's really only the syntax that's the same; the .NET framework is totally different to MFC.

June 30, 2006 7:24 PM


Anonymous said...
Hi Simon
you're just great! It worked!
Thank you, Peter

July 26, 2006 1:06 PM


Simon said...
Thankyou Peter, glad you liked it. To be fair, I probably wouldn't have posted it if it didn't work ;-)

July 28, 2006 12:49 PM


Anonymous said...
That Work Thanks a million!!!
George

September 08, 2006 8:52 AM


Anonymous said...
Hi Simon

Thanks a lot! I kiss your feet ....

Greets
Benni

September 14, 2006 8:37 AM


Simon said...
Ha, thanks Benni!

September 14, 2006 8:41 AM


Anonymous said...
Grazie 1000 (thanks a lot)
daniele

September 27, 2006 6:45 AM


Mohan said...
Hi Simon,

While i appreciate the fact that turning this off will allow us to continue to debug, i am worried whether there is actually some deadlock occuring while calling COM interops (like MS Word interop components)... and will result in app crashing at a later time..

Just thinking..

Cheers
Mohan

October 11, 2006 4:15 PM


Simon said...
Good point Mohan. I've not done anything with COM interops, so it's not an issue for me yet. You can always switch it back on again when debugging something of that nature.

October 11, 2006 8:30 PM


Anonymous said...
Thank you sooooo much!! This was driving me NUTS trying to debug my programs in 60 seconds or less. My next question is WHY do they tell you to create a application.mda.config file that it just ignores anyway?! It's SO much easier to just go to a menu and click a checkbox!! (pant pant) Ok, I'm done. Thanks again.
- John

October 12, 2006 4:50 PM


Anonymous said...
Thanks alot........... it was soooo very helpful..............

Thanks Thanks Thanks Thanks

October 17, 2006 12:46 PM


Nitin said...
Thanks a Ton!! Really Eased the Pain.

October 27, 2006 2:25 PM


Anonymous said...
Hi all,
It was helpful for me in debugging C# application.
It was really annoying.

Thanks a lot!!!!!!!!
Zevik

October 27, 2006 5:13 PM


Anonymous said...
Add one more grateful person to your list! Thanks! That thing drove me crazy, and MSDN was no help.

November 03, 2006 8:17 PM


Anonymous said...
Thanks so much. You are my hero!

November 03, 2006 10:58 PM


Anonymous said...
My menu doesn't have that option (Exceptions). I'm using the final release of VS 2005. I go to Debug and all I have for options are: Windows, Start Debugging, Start Without Debugging, Attach to process, Step Over, Toggle Breakpoint, Delete All breakpoints.)

Am I looking in the wrong place? Thanks!

November 08, 2006 10:10 PM


Simon said...
No, that should be the right place. I don't know why it doesn't show up on yours. The shortcut key on mine is Ctrl-D, E. Maybe that will work for you.

November 09, 2006 9:28 AM


Anonymous said...
thanks a ton 4 this shortcut

November 14, 2006 4:10 PM


Anonymous said...
Simply add the "Exceptions" menu-item, by choosing

Tools - Customize

Categorie "Debug", click and hold "Exceptions..." (from the commands pane), and drag it to your Debug menu.

So if you have other menu-items missing, just dollow the same routine.

Johan

November 20, 2006 10:34 AM


Anonymous said...
Hey gracias, me han salvado de un dolor de cabeza.

December 06, 2006 6:13 PM


Simon said...
Eres muy agradable. ¡Me causó absolutamente un dolor de cabeza!

December 08, 2006 5:25 PM


Anonymous said...
Hi guys!

I think I'm more grateful to Johan than Simon because my colleagues and I have been searching forum after forum and could not find the 'Exceptions' in our Debug menu!! So so frustrating until we read Johan's simple tip to drag it there. Thanks a million Johan!

You have just helped the government of Australia! :)

Himanshu

December 11, 2006 12:24 AM


Anonymous said...
If your ContextSwitchdeadLock was caused by some really heavy looping (like in my case - constructing tables out from large set of row data)you can avoid the lock by calling Application.DoEvents(); in C#. It processes the event queue and the MDA knows the application is doing fine and won't forcecrash it.

Tero Rönkkö - www.ronkko.fi

December 11, 2006 5:14 AM


Anonymous said...
thanks harriot.. thats a lot of help buddy...
- dexter

December 11, 2006 1:11 PM


Preston said...
Tero's solution of calling Application.DoEvents(); works well and has the advantage of keeping the form repainting when needed while a long process runs.

February 12, 2007 10:41 PM


Eych said...
THANKS!!!

February 14, 2007 1:38 PM


Anonymous said...
Thanks a lot;

March 12, 2007 1:56 AM


Michiel Wiegers said...
And another Thanks! This anoying thing is a waste of time and causing me every time to startover again.

March 20, 2007 11:02 AM


Anonymous said...
Thank you very much. This has solved a big pain in the rear and I also learned something else helpful with the comments about Application.DoEvents.

March 27, 2007 11:54 PM


Rick said...
So, let me see if I get that error message right:

After COM and VisualStudio shacked up (context/apartment), COM wouldn't put out (non pumping), spent all VisualStudio's $$$ (usage over time) and VisualStudio got primitive on COM's ass (negative performance impact).

I understand it completely.

March 28, 2007 3:29 PM


Anonymous said...
Thanks a lot man!!!

Best regards from Spain

April 03, 2007 9:29 AM


Vlad said...
Thank you very much, you have saved my a lot of time.

April 04, 2007 3:22 PM


Anonymous said...
Hello to all

I am just not able to find the exception part in the menu or able to add through what JOHAN has written. Please help me as I am not able to get rid of this error and it is driving me nuts.

-Rahul Sharma

May 01, 2007 10:46 AM


Anonymous said...
Ctrl+Alt+E from within VS.2005 will bring up the dialog he mentioned.

May 02, 2007 2:45 PM


Anonymous said...
Tnx dude, finally a post worth looking @ ;)

Grtz

May 24, 2007 11:13 AM


Anonymous said...
You guys are the best of Visual Basic world. Thanks .....

June 14, 2007 1:39 PM


Anonymous said...
Thanks mate!

Its an annoying thing, so why is it by default checked?

July 18, 2007 10:47 AM


Anonymous said...
Hello Simon,
Thank you very much..

Best Regard,
Syira
Malaysia

July 25, 2007 4:33 AM


Anonymous said...
That has been driving me bonkers!

Thanks very much for this simple solution. The MS site has a complete article explaining about this (which doesn’t work). Very much appreciated.

August 16, 2007 3:46 PM


JFalter said...
Thanks so much. This thing has been driving me nuts!

August 28, 2007 4:35 PM


Anonymous said...
Thanks for that....that was getting to be a pain in the but...I had to hurry up and do my debugging in 60 seconds....sucked.

September 01, 2007 8:58 PM


Anonymous said...
Debug --> Exceptions menu pick missing. Was I losing my sight? My mind? No, just yet another VS 2005 quirk. If you want to follow the above steps, but your Debug | Exceptions menu pick is missing, as mine was, display it with Ctrl + Alt + E or go to this handy post to get it back: http://blogs.vertigo.com/personal/KeithC/Blog/Lists/Posts/Post.aspx?ID=16

September 13, 2007 3:25 PM


Bobby said...
i also got this problem -----
The CLR has been unable to transition from COM context 0x1c3008 to COM context 0x1c3178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

i had done all the things, including

this,
Debug -> Exceptions -> Managed Debug Assistants
and unchecking the ContextSwitchDeadlock item.

and also this in config file



contextSwitchDeadlock enable="false"



but problem is not going to solve.
can any one suggest me ????
i am waiting for ur (all of programmer)reply

October 08, 2007 9:00 AM


Anonymous said...
Thanks for the info about disabling the MDA notification. Also, tip on using Application.DoEvents() was very helpful

February 13, 2008 10:02 AM


Anonymous said...
la verdad no me funciono nada, lo unicco que consegui, es que la memoria se disparara hasta los 2.5 Gb en RAM, saludos, espero encontrar una solucion

April 28, 2008 2:02 AM


Anonymous said...
Thank soooo much

May 15, 2008 4:39 PM


Anonymous said...
Hey guys,
Just disabling the messgae is not solution for this issue. My application keep on wiating ta same place and its not returning the control to execute next statement.
What could be the problem
Thanks,

July 01, 2008 3:35 PM  
Anonymous Anonymous said...

ok, gracias si nos sirvió.
cquirosm

July 18, 2008 8:55 PM  

Post a Comment

Links to this post:

Create a Link

<< Home