Hello,
Im trying to do something very simple but having problems..
What I want to accomplish sounds simple but I cant find anywhere on the web answer of how to do that so it will work.
I want to run a thread , for example map the files on the hard drive.
now what I want to do is run a timer that will check the thread state so when it is finish the timer will run a second thread that will map the files on the hard drive again but with different params this time.
the problem I am facing is that after i do thread.start if i define a new timer that will check the function of the timer cant find the thread.
here is example code just to illustrate:
public string Scan(string id)
{
// Create the thread object
// via a ThreadStart delegate. This does not start the thread.
Thread z = new Thread(delegate() { SearchDrive("*.exe"); });
//Start the thread
z.Start();
//here I want to start a timer that will check the thread state
//so i do it as MS say
system.Timers.Timer aTimer = new System.Timers.Timer();
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
}
// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//How can I make a z.threadstate check her ?
I want every 2 seconds to check if thread is still active.
and if it is finished running I want to run
Thread x = new Thread(delegate() { SearchDrive("*.dll"); });
//Start the thread
x.Start();
}
I thought maybe fighting with threads which i dont know well,
maybe i should add to the functions i run in threads to write to a
status file when they finish running and then simply add regular timer that checks
the status and runs the next function.
any help will be appreciated,
Thanks.