schenkp
asked on
Application Exit Checking
HI,
I am having an issue with a couple of methods in my program.
Is there a way I can check and see if any of these threads are running and if not the software goes by it without crashing?
EC0-EC270 are programs
EC4-EC7 are forms off of the main
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
}
private void exitToolStripMenuItem_Clic k(object sender, EventArgs e)
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
Application.Exit();
}
private void resetApplicationToolStripM enuItem_Cl ick(object sender, EventArgs e)
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
Application.Restart();
}
I am having an issue with a couple of methods in my program.
Is there a way I can check and see if any of these threads are running and if not the software goes by it without crashing?
EC0-EC270 are programs
EC4-EC7 are forms off of the main
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
}
private void exitToolStripMenuItem_Clic
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
Application.Exit();
}
private void resetApplicationToolStripM
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
Application.Restart();
}
ASKER
Hi Zepher,
ECO, EC90, EC180, and EC270 are real programs that get launched when the user click on a button on the main program.
There path is C:\program files\mysuff\ECO.exe, etc
EC4, EC5, EC6, and EC7 are all forms that get launched from the main program when a user click on the same button.
What happens is the user makes a choice and EC0, EC4, and EC90 are launched (for example) so now we have the main program, one form( EC4) and 2 external programs (EC0, EC90) are running. No i have a timer that executes and usess StuffandKill();
EC0, EC4, and EC90 all close down they way they should, but after this if the user clicks on any of these methods
Appliation.Ext();
KillAndStuff()
Application.Rest();
KillAndStuff()
Form_closed();
KillAndStuff()
The application throws up and exception and says that EC0;
System.InvalidOperationExc eption was unhandled
Message="Cannot process request because the process has exited."
Source="System"
StackTrace:
at System.Diagnostics.Process .GetProces sHandle(In t32 access, Boolean throwIfExited)
at System.Diagnostics.Process .Kill()
So i was thinking that maybe the KillandStuff() methode needs a little error checking or something?
ECO, EC90, EC180, and EC270 are real programs that get launched when the user click on a button on the main program.
There path is C:\program files\mysuff\ECO.exe, etc
EC4, EC5, EC6, and EC7 are all forms that get launched from the main program when a user click on the same button.
What happens is the user makes a choice and EC0, EC4, and EC90 are launched (for example) so now we have the main program, one form( EC4) and 2 external programs (EC0, EC90) are running. No i have a timer that executes and usess StuffandKill();
EC0, EC4, and EC90 all close down they way they should, but after this if the user clicks on any of these methods
Appliation.Ext();
KillAndStuff()
Application.Rest();
KillAndStuff()
Form_closed();
KillAndStuff()
The application throws up and exception and says that EC0;
System.InvalidOperationExc
Message="Cannot process request because the process has exited."
Source="System"
StackTrace:
at System.Diagnostics.Process
at System.Diagnostics.Process
So i was thinking that maybe the KillandStuff() methode needs a little error checking or something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
Works great:)
Works great:)
private void KillAndStuff()
{
if (EC0 != null)
EC0.Kill();
if (EC90 != null)
EC90.Kill();
if (EC180 != null)
EC180.Kill();
if (EC270 != null)
EC270.Kill();
if (ec4 != null)
ec4.Close();
if (ec5 != null)
ec5.Close();
if (ec6 != null)
ec6.Close();
if (ec7 != null)
ec7.Close();
}