I’m in to a loop defined dynamically the function that will run onClick of control.
the function is the following:
public static void TryOpenFile(string filename, EventHandler callback)
{
Process proc;
proc = Process.Start(filename);
if (callback != null)
{
proc.EnableRaisingEvents = true;
proc.Exited += (a, b) =>
{
callback(a, b);
};
}
}
And then:
for(int i = 0; i < numberOfControls; i++)
{
controlImg.SetFileToOpen(file,
delegate
{
//exited!
});
}
The documentation for this overload of Process.Start explains what is happening (emphasis mine):
A new process may not be started if you are using ShellExecute to start a file using it’s association, rather than running an executable. For instance, if
filenameis (for example) “C:\Test.xls”, it might start Excel. But if Excel was already running, it might open the file in the existing running instance, rather than starting a new process. In that case, the value ofprocwould be null.