Solved

ContextSwitchDeadlock exception?

Posted on 2012-03-22
6
670 Views
Last Modified: 2012-03-22
I got  the following exception, ContextSwitchDeadlock:
"The CLR has been unable to transition from COM context 0x3422fb0 to COM context 0x3423120 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."

Anybody any experience with this exception?
0
Comment
Question by:Labelsoft
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 37752037
Are you doing any long running tasks within an event handler of your form?
0
 
LVL 3

Author Comment

by:Labelsoft
ID: 37752041
Yes, I am. Could that long running task prevent the form from pushing windows messages?
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 37752332
Yes it can.  If you have a long process to run, or a blocking call, then put it on a different thread.  The BackgroundWorker() control can make this task much easier:
http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37752339
*If you have have a long running LOOP, then a "quick fix" is to place Application.DoEvents() INSIDE that loop to pump the message queue.  Properly threading the solution is a better approach though.
0
 
LVL 3

Author Closing Comment

by:Labelsoft
ID: 37752393
Kaufmed already hinted me to the 1st solution Idle-mind gave. As I was waiting for kaufmed, I implemented the backgroundworker and it worked. So I'm awarding both with points. Thank you both very much for replying.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37752735
Sorry, I was on my way to work. Glad you got it sorted out  : )
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question