7

When I Run My Application After Some Second This Exception Occurred. what is exception and How I Can Handle This Exception

The CLR has been unable to transition from COM context 0x647f10 to COM context 0x648080 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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
ali kiani
  • 877
  • 1
  • 14
  • 29
  • 8
    Reading Text With Every Word Capitalized Is Annoying – Matti Virkkunen Dec 07 '11 at 18:23
  • The description of what happened is all in there, although it can be a bit unclear how you triggered it. To get help you will need to be much more specific on what your application does and how it is built. – Anders Abel Dec 07 '11 at 18:24
  • I Have Work On Sudoku With Generic Algorithm And maybe a lot of time To find answer and this exception occurred. – ali kiani Dec 07 '11 at 18:35
  • 1
    possible duplicate of [Visual Studio: ContextSwitchDeadlock](http://stackoverflow.com/questions/578357/visual-studio-contextswitchdeadlock) – Brian Hooper Jun 11 '15 at 09:52

2 Answers2

8

This typically occurs if you have something blocking your user interface thread, and are using COM components.

The best approach here is to move your long running operation into a background thread. This leaves your UI responsive, which also means that the COM messages can pump correctly. BackgroundWorker is a nice tool for this.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
0

In my experience this results from having a long-running task in the main thread of a windows form. Consider using a BackgroundWorker to run the task instead. The immediate benefit of doing this will be that your UI won't appear to freeze while the task is running. You might even look into implementing a progress bar using the ProgressChanged event.

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181