Hi,

There are multiple threads runing in my application, the application is very huge. A client server architecture, though the client stops, the server keeps running at the back ground.
It so happens that sometimes, even after i click the exit button which has "this.Close()" called inside the click event handler, the client still survives in the process, the only work around is to kill the process and start again, client is mutex.

Any help appreciated.
Thanks.

Try Application.Close() or Environment.Exit(int) methods. this.Close() closes the form but doesn't shut down the application.

I wrote Process.GetCurrentProcess().Kill(), is this right, am not sure if this is a perfect piece of code for the requirement.
how does Application.Exit and Application.Close differ with each other ?

Environment.Exit() allows you to pass an error code integer like many console applications do when they complete their execution. Application.Exit() is probably the best method as this indicates that the application is complete without error. Both methods will terminate threads of execution and dispose of the memory objects cleanly.
I have never used Process.GetCurrentProcess().Kill() but I think this might not be enough to close an application in some circumstances?

EDIT: My earlier post listed Application.Close() -- this should be Application.Exit() - sorry for the confusion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.