Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I'd like to understand a problem I'm currently facing.

I created a C# application using Winforms. I have a long running operation (several minutes).
When I launched this operation to test it directly in one of my control in the GUI layer (say, "onButtonTestClicked()"), the windows was frozen as I expected, and the application grew and grew up to 2 giga in memory(!), causing this OutOfMemory exception.
However, when I launched my long operation in a new thread from onButtonTestClicked(), it used only up to 200 mega.
I suspect this issue is linked to Windows message pumping: when the app is frozen, it can't pump messages as it should. But what is the link with all that memory space taken?

Could you explain why? I'm quite curious about it.

Thanks !

What I have tried:

Well, I didn't find much on the internet. Here is some piece of documentation: About Messages and Message Queues (Windows)[^]

When debugging, I have this error message:
The CLR has been unable to transition from COM context 0x1a0b88 to COM context 0x1a0cf8 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.
Posted
Updated 29-Jan-18 4:30am
v3
Comments
Dave Kreskowiak 25-Jan-18 11:56am    
There isn't a relationship.

Without seeing the relevant code, it's impossible to tell you what you're doing wrong.
ZurdoDev 25-Jan-18 13:33pm    
I agree with Dave. There is likely something else going on.
SheepSpeech 26-Jan-18 4:28am    
Well I can't give you the code because this is a project I'm on with other people. But I can tell you that I'm using Entity Framework, and the long operation is generating entries for a database.
Anyway, the only difference between both cases is the new thread creation.

I added the error message I get when I'm in debug mode. The interesting part is "or memory usage accumulating continually over time". It seems to be related in some way...

Do you have any ideas, even vague? It might help me find out what's relevant here.
Richard MacCutchan 26-Jan-18 5:10am    
The only way to find out is to debug your code. As commented above it is impossible to make even a vague guess as we have no idea what your code is doing.

Quote:
What is the relation between windows message pump and outofmemory exception?

There is no relation between them. Or the relation is your code.
Your app stopping the messages pump is a secondary effect of your app being busy allocating memory, but without seeing your code, it is difficult to tell.
 
Share this answer
 
Comments
SheepSpeech 26-Jan-18 10:56am    
Thanks. But then how do you explain this part of the error message: "or memory usage accumulating continually over time"? As I said, it seems to be related in some way...
Don't block the gui for so Long - users will get the "application not responding" message in release mode. So use threads. And your second problem seems to come from your Debugging - when you set a breakpoint in a time-critical function (there is a timeout for SQL-Access e.g.) you will see the timeout occur.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900