Non pumping wait error?

Non pumping wait error?

Old forum URL: forums.lhotka.net/forums/t/3811.aspx


david.wendelken posted on Tuesday, October 30, 2007

What does this error message mean?  Is it a CSLA issue? Or a windows one?  What can I do?

I have a windows program that is a code generator, it builds classes, web pages, etc.  But when I run it against a database with lots of tables, I get this error:

Managed Debugging Assistant 'ContextSwitchDeadlock' has detected a problem in 'D:\Source\ABCD\CodeGenerator\bin\Debug\Codegenerator.vshost.exe'.
Additional Information: The CLR has been unable to transition from COM context 0x1b1c88 to COM context 0x1b1df8 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.

 

ajj3085 replied on Tuesday, October 30, 2007

Hmm.. sounds like your log running operation should be put into a BackgroundWorker_DoWork method.  Or manually create another thread to do the long running process.

david.wendelken replied on Tuesday, October 30, 2007

ajj3085:
Hmm.. sounds like your log running operation should be put into a BackgroundWorker_DoWork method.  Or manually create another thread to do the long running process.

I'm guessing that BackgroundWorker is a class?  I am really new to windows stuff.

ajj3085 replied on Tuesday, October 30, 2007

Oh sorry.  BackgroundWorker is a Forms component (its in the Components tab of your toolbox).  So whatever form has the code that is long running you'll add this component to.  Then you'll wire the BW's DoWork and RunWorkerCompleted; in DoWork, you'll perform the long running operation.  In RWC (or something along those lines) you'll re-enable the form.    The typical pattern is this:

private void button_click( object sender, EventArgs e ){
  this.Enabled = false; // don't disable the whole form, but this is an exampel..
  myBackgroundWorker.RunWorkerAsyn(); // or you can pass an object if you need arguments in DoWork
}

private void myBW_DoWork( object sender, DoWorkEventArgs e ) {
   e.Result = DoLongRunningTask(); // Result is an object; so pass whatever you need to
}


private void myBW_RunWorkerAsyncComplete( object sender, RWAC e ) { // forget the exact name..
   string result = (string)e.Result; // Will throw an Exception if an exception was thrown in DoWork event
   this.Enabled = true;
   MessageBox.Show( "Done!" );
}


That's the basics; check out the MSDN help topic for BackgroundWorker component, you'll find all the info you need.

david.wendelken replied on Tuesday, October 30, 2007

Thanks!

Copyright (c) Marimer LLC