How to pass object to Process Class Exited() event?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Having trouble determing just how to pass a parameter (object) to the Process
Class' Exited() event?

Too dense to understand the documentation. Please just a simple example.
Using C#, but can understand C or Basic.

Here is my code:

Process p = new Process();
: : :
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
p.Start();

: : :

void p_Exited(Object sender, EventArgs e)
{
: : :
}

I want to pass an object reference into this Event.

Thanks much.
 
Jeff said:
Having trouble determing just how to pass a parameter (object) to the
Process
Class' Exited() event?

Too dense to understand the documentation. Please just a simple example.
Using C#, but can understand C or Basic.

Here is my code:

Process p = new Process();
: : :
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
p.Start();

: : :

void p_Exited(Object sender, EventArgs e)
{
: : :
}

I want to pass an object reference into this Event.

You can't "pass" an object into the event handler.

Is this code part of class? Put the object in an instance member:

class ProcessRunner
{
object _someObject = new object();
public void Starter()
{
// ...
Process p = new Process();
: : :
}

private void p_Exited(Object sender, EventArgs e)
{
// use _someObject here.
}
}
 
I actually ended up with this for the solution:

class myProcess : Process {
private Object _obj;

public myProcess(object obj) {
_obj = obj;
}

public Object getObj {
get { return _obj; }
}
}

// I instantiate an object of myProcess instead of Process
// and, the Exited() event actually passes a pointer to myProcess.
// So that now in the Exited event, I can access that object.
// I guess I had assumed that the Exited event would still only
// pass a pointer to the Process class object.

myProcess p = new myProcess(myObject);
p.Exited += new EventHandler(p_Exited);
p.Start();

: : :

void p_Exited(Object sender, EventArgs e) {
myProcess p = sender as myProcess;
Object myOriginalObject = p.GetObj;
}

problem solved...

thanks again
 
Back
Top