Helps with over processing

Asked

Viewed 2,764 times

0

I am writing an application in C#. My application works well processing up to a certain amount of data. However, if this amount of data increases significantly, it enters a state named by Visual Studio as "state of interruption" and displays the following message:

Contextswitchdeadlock Managed Debugging Wizard: 'CLR failed to transition from COM 0x9e58a0 context to COM 0x9e57e8 context in 60 seconds.`

The thread that has the target context/Apartment is probably waiting without pumping or processing a very long run operation without pumping Windows messages. Generally, this situation has a negative impact on performance and can even lead to lack of application response or to continuous accumulation of memory usage over time`.

To avoid this problem, all threads with a single thread Apartment (STA) must use pumping standby primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long run operations.'`

In my case, the thread is performing a very long operation "no pumping of Windows messages".

Until then, I never had to deal with it.

How can I fix this? It can be a chunk of code (it doesn’t have to be in C#, any pseudo code helps).

  • 1

    If competition is a problem a possibility is to implement processing queues. Create a Worker that gets the 'tasks' from a FIFO queue.

  • Is there a way to illustrate this in code? A class?

  • 1

    This can give you a light: http://stackoverflow.com/questions/22688679/process-queue-with-multithreading-or-tasks

  • https://msdn.microsoft.com/en-us/library/hh228601(v=vs.110). aspx

1 answer

2


Usually this occurs when there are long processing and the Debugger thinks it is a Deadlock but it’s not necessarily!(it’s just a warning) This only happens in debug mode, to disable this warning just go to the menu Debug > windows > Exception Settings look for Contextswitchdeadlock and disable the option

  • But in real operation mode the program explodes! I think the solution has something to do with the Cowaitformultiplehandles highlighted class, so I’m asking for a code snippet.

  • There is no way to create a piece of random code to exemplify this, could post your code to analyze better?

  • @Paul the correct one would be you provide the flawed code not? After all the problem occurs in your code due to error message "The thread that has the target context/Apartment is probably waiting without pumping", This refers to your code, it does not do much to post any code here, and there are numerous ways to cause this problem. Edit your question and post the relevant code =)

  • My code is fine. The problem is that I need to keep incoming messages from windows active while running my code processing. I mean, it’s about keeping two theards active. But, I don’t know how to do that.

  • You’re right. It wasn’t threard problem that was making my program break. But, something within the long process. The lack of processing windows messages causes the message in the program interface: "app.exe (not responding)". In my case the program was breaking even.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.