How to dispose all resources after closing the application ?
-
Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai
-
Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai
taibc wrote:
After closing my application, there is still a running process that showed in the Task Manager.
Do you know, how to dispose all resources after I close my C# application ?All .NET objects will be disposed of by the runtime. Did you launch a (non-background) thread?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
taibc wrote:
After closing my application, there is still a running process that showed in the Task Manager.
Do you know, how to dispose all resources after I close my C# application ?All .NET objects will be disposed of by the runtime. Did you launch a (non-background) thread?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,
-
Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,
Actually, that'll leak resources, not close them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,
taibc wrote:
I found out a way to do that by use the statement:Process.GetCurrentProcess().Kill();
There's no book that recommend thus. It might "feel" as a fast way to exit the app, but as you noticed, it doesn't exit nicely. You might wanna research the difference between foreground and background-threads. I'll bet one of them is still running.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Actually, that'll leak resources, not close them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai
taibc wrote:
Do you know, how to dispose all resources after I close my C# application ?
Wrong question. Presumably your application only has one process - if not then you must have started the other processes so stopping them is also required. But excluding that then if your application (process) is still running after you "close" it then that means you started a thread that continues to run. So the solution is that when you "close" it that you must terminate the threads that you started. And the terminology is not apt since it isn't a matter of "resources" - it is an application/process which has not terminated. Once the process terminates all of the resources are freed regardless of the action your application took.
-
Dave Kreskowiak wrote:
Actually, that'll leak resources, not close them.
What resource do you think will be leaked after the Process exits?
Off the top of my head, anything that holds an unmanaged handle, such as GDI objects: Brush, Pen, Graphics, ... That's by no means a complete list of the stuff that can be orphaned, just a sample.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Off the top of my head, anything that holds an unmanaged handle, such as GDI objects: Brush, Pen, Graphics, ... That's by no means a complete list of the stuff that can be orphaned, just a sample.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I doubt that a Process will hold on to any of those when the Process exits, regardless of how it exits.
I wouldn't bet on that - from experience.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I wouldn't bet on that - from experience.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Dave Kreskowiak wrote:
I wouldn't bet on that - from experience.
Then it is an OS bug. "•Any resources allocated by the process are freed." http://msdn.microsoft.com/en-us/library/windows/desktop/ms686722(v=vs.85).aspx[^]
Maybe not. It may depend on if you run the system out of resources first. My experience was killing a process that leaked handles like crazy. Once you exhaust the handle pool, Windows starts to loose it's mind.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Maybe not. It may depend on if you run the system out of resources first. My experience was killing a process that leaked handles like crazy. Once you exhaust the handle pool, Windows starts to loose it's mind.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
XP (any SP version)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak