How can I pass arguments to the function I want to run in a new thread? I'm currently working around it like this, but could cause problems if the same instance of my class runs the procedure twice in a row.
PHP Code://....
private string sTempFile;
private Process pTempProc;
//....
private void KillFile()
{
//wait for the process to exit and kill the file.
//i want to pass a process and a filename
//to this function when i start it in its own thread.
pTempProc.WaitForExit();
File.Delete(sTempFile);
}
public void Execute(string sFileName, bool WaitAndCleanup)
{
sTempFile = this.Unpack(sFileName);
pTempProc = new Process();
pTempProc.StartInfo = new ProcessStartInfo(sTempFile);
pTempProc.Start();
if (WaitAndCleanup)
{
Thread th = new Thread(new ThreadStart( KillFile ) );
th.Start();
}
return;
}





Reply With Quote