James0886

Hello all. i got this prob when i close my app and i open the task manager the process is there in the list how can i make sure that when the user closes my app is going to close not stay on the task manager.


thx in advance.


Re: Visual C# General closing app probs

Andreas Johansson

Usually closing the form will be enough but if you have started multiple message loops by calling Application.Run() you usually can make all message loops end by calling Application.Exit().

This might not be the solution for you but to help you further you need to give more details about your app and how you do to exit it.






Re: Visual C# General closing app probs

ahmedilyas

Perhaps your application is still doing something in the background Such as creating another thread which is still running and hasnt finished yet

What does your application exactly do Are you sure your are not looking at the application.vshost instance in task manager whilst you are running an instance of VS with that solution loaded (some people do get confused)






Re: Visual C# General closing app probs

James0886

ahmedilyas wrote:

Perhaps your application is still doing something in the background Such as creating another thread which is still running and hasnt finished yet

What does your application exactly do Are you sure your are not looking at the application.vshost instance in task manager whilst you are running an instance of VS with that solution loaded (some people do get confused)




the aplication uses a while loop(BoolExit =! false) to check if a process is running.
if the process exited the app will start the process again.(a restarter)
If i click the stop Button (BoolExit = true) and the loop will break.
Some of the user i got they dont click the stop button they only click the X button to exit. the while loop stays open and the app windows closes, and the process keeps restarting.




Re: Visual C# General closing app probs

ahmedilyas

its bad practice really to have it keeping it in a loop. Why dont you use the Process's Exit event to catch the event to see if a process has exited

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.aspx

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process_events.aspx

It's much better and more efficient too

Does this help Does this resolve your problem I hope it is heading into the right direction and hope that it does resolve your problem






Re: Visual C# General closing app probs

James0886

thx alot for the help.

heres the code i use:



Code Snippet

public static void RestRealm1()
{

int toint1;
toint1 = Convert.ToInt32(Config.Default.ATime1);
realm1.StartInfo.WorkingDirectory = Config.Default.app1;
realm1.StartInfo.FileName = Config.Default.appName;
realm1.Start();


while (start1 != false)
{

Thread.Sleep(toint1);
if (start1 == false)
{
continue;
}
if (app1.HasExited)
{

app1.Start();
SystemSounds.Beep.Play();

}

}


}
public void tofalse1()
{
start1 = false;

}



I use a while loop because i whant my app to restart the program more the 1 time.





Re: Visual C# General closing app probs

ahmedilyas

if you want your app to restart a program again, just as suggested previously, use the Process class's Exit event to indicate if the process has exited, once done then restart that process instead of having this unneeded while loop :-)






Re: Visual C# General closing app probs

Peter Ritchie

Your problem is due to the fact you're ensuring your thread can't exit for toint1 milliseconds; which means your application cannot exit either. You might want to read Thread.Sleep is a sign of a poorly designed program.