[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

ContextSwitchDeadlock exception?

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
Labelsoft
Asked:
Labelsoft
  • 2
  • 2
  • 2
2 Solutions
 
käµfm³d 👽Commented:
Are you doing any long running tasks within an event handler of your form?
0
 
LabelsoftAuthor Commented:
Yes, I am. Could that long running task prevent the form from pushing windows messages?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*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
 
LabelsoftAuthor Commented:
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
 
käµfm³d 👽Commented:
Sorry, I was on my way to work. Glad you got it sorted out  : )
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now