The following console application is working fine - I was surprised that this is not an error.
class DelegateExperiments
{
private const string helloText = "hello world";
private const string exitText = "you just closed notepad";
private Process myProcess;
static void Main(string[] args)
{
Console.WriteLine(helloText);
DelegateExperiments myInstance;
myInstance = new DelegateExperiments();
myInstance.Foo();
Console.Read();
}
void Foo()
{
myProcess = new Process();
myProcess.StartInfo.FileName = @"notepad.exe";
myProcess.Exited += MyProcessExited;
myProcess.EnableRaisingEvents = true;
myProcess.Start();
}
private void MyProcessExited(Object source, EventArgs e)
{
Console.WriteLine(exitText);
}
}
If I try to do something similar with winform, I will write the message back to the form label, then it will be more complex and needs a line to work myProcess.SynchronizingObject = this;. Why should they be different?
source
share