Process.Exited

dannyres

Regular
Joined
Aug 29, 2003
Messages
67
Hi guys, im trying to work out how i can make a program run, then once its exited do something else... I see there is a Exited Event in the process object, but when i try to handle it, it doesnt seem todo anything when the app is exited... anyone know how todo this?



Dan
 
What sort of thing do you want the app to do?
Since the app doesn't exist enymory it can't do enything else... has its logic!...

What you can do is, when the app is closing, lounch another windowless app that does what you want... or simplyer, use the Sub Main!... start the program with a show dialog form on the sub main... only when that form is closed the following code on the sub main is executed... simple... :)

Tell me if you understood...
 
I'm not sure but I think he is talking about using the Process class to start an exe file on the hard drive, not one of his own programs.

You could just monitor the Running processes and when the process you are looking for is no longer in the list, you know it is closed.
 
yeah i want todo what aewarnick said, but i think i can use the exited event... anyway if i cant, how would i do what you said?



Dan
 
This is a snippet from one of my programs:
C#:
public void FillRunProc()
		{
			Process[]P= Process.GetProcesses();
			bool there=false;

			foreach(Process p in P)
			{
				foreach (string x in this.runProcLB.Items)
				{
					if(p.ProcessName==x)
					{
						there=true;
						break;
					}
				}
				if(!there)
					this.runProcLB.Items.Add(p.ProcessName);
				there=false;
			}

			there=false;
			string[]listProc=new string[this.runProcLB.Items.Count];
			this.runProcLB.Items.CopyTo(listProc, 0);

			foreach (string x in listProc)
			{
				foreach(Process p in P)
				{
					if(p.ProcessName==x)
					{
						there=true;
						break;
					}
				}
				if(!there)
					this.runProcLB.Items.Remove(x);
				there=false;
			}
		}
 
try this...
Visual Basic:
    Dim WithEvents pr As Process

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        pr = Process.Start("iexplore.exe", "about:blank")
        pr.EnableRaisingEvents = True '/// make sure raising events is set to True.
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not pr.HasExited Then
            pr.CloseMainWindow()
        End If
    End Sub

    Private Sub pr_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles pr.Exited
        MessageBox.Show("closed!")
    End Sub
 
Back
Top