Click here to Skip to main content
15,885,078 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
So i have this pseudo-code in C#:

C#
While (My Program is Running){
 // check if another program is running from processes
 // if its true, do something else nothing
}


i found out that after 30/40 mins of my program running it starts to use all RAM memory and i have to force close it to clean the usage of memory. so my question is, what do i do? should i clean memory on code? should i use while loop?

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Dec-13 14:52pm    
Doing what you are doing is a huge abuse. Why doing so? Are you familiar with threading?
If you clearly explain your ultimate goals, perhaps I can tell you what to do.
—SA
Adam Zgagacz 4-Dec-13 14:59pm    
There is nothing wrong with while loop in C# language. Problems are cause by the code you are not showing us (whatever you are doing in the loop is wrong).
Sergey Alexandrovich Kryukov 4-Dec-13 15:32pm    
You just did not understand me. Who told you anything about "while loop"? The idea is extremely bad. This is not code, this is pseudo-code with "spin wait" doing some job in cycle. It's hard to invent something worse.
—SA
ZurdoDev 4-Dec-13 14:57pm    
You'll need to post your actual code. It sounds like you are leaving things open.
TnTinMn 4-Dec-13 15:51pm    
Presumably you are getting one or more instances of the Process Class (http://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx). Are you calling the Dispose Method on the Process instance when you are done with it? Probably not.

But as others have stated, "SHOW THE CODE" and then maybe you will get something useful.

1 solution

This is really only answer could be given:
Without seeing the code nobody can tell what's wrong with it.

How are you checking if process is running?

Also consider everything what was said in comments. Be careful what you are doing. Tight loop running continuously is very bad idea. With threading periodical checking for process it might work. Just be careful.
 
Share this answer
 
Comments
agent_kruger 7-Dec-13 7:03am    
sorry as you are senior but please do not use answer to increase your points. Sorry if the above language was rude.
Adam Zgagacz 7-Dec-13 15:11pm    
I didn't mean to offend you. Sorry. But seriously, if you want different answer, you need to show the code. Otherwise nobody can guess.

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