Tuesday, November 10, 2009

what to do when long running threads don't respond

Additional Information: The CLR has been unable to transition from COM
context 0x189558 to COM context 0x189408 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.

=======================

One simple remedy is the following

there are 2 things to try
1. goto "Debug", "Exceptions..." menu
2. Managed Debugging Assistants, uncheck ContextSwitchDeadlock

Or you can try following

=============================
Call routinely CurrentThread->Join(0), this implicitely calls
CoWaitForMultipleHandles and returns.




Thanks willy, this is working and pumping message.
But on my form, i have a label and a progress bar.
During this time, the progress bar is refreshed, but not the label.
Should i call an explicit update ?

This is my code :
this->Show();
this->Update();
for each(entry in entries)
{
TreatmentForOneOr2Secs();
this->progressBar1->PerformStep();
System::Threading::Thread::CurrentThread->Join(0);
}
this->Hide();

("this" is the form)

Do you know why the label isn't refreshed ?

No comments: