Have forgotten my ways with threading!
I just want to make sure the thread will stop after the call. This code executes under the timer1. Im assuming that after the thread is created and the function finishes, the thread terminated itself. I wated process under ctrl,alt, delete and I am fairly confident it is working.
Am I correct, ( Im worried Im creating a problem down the road)???
Thanks
private void timer1_Tick(object sender, EventArgs e){
Thread t = new Thread(runningTimer);t.Start();
}
private void runningTimer(){
System.Net.WebRequest req = System.Net.WebRequest.Create(grate.ToString() + "?wsdl"); try{
m_wr = req.GetResponse();
m_wr.Close();
}
catch{} if (m_wr != null){
bconnected = true;}
else{
bconnected = false;}
m_wr =
null;}
Sergio FonsecaPosted Mar 27, 2008, 9:23 PM
System.Threading.
Thread t; //You must declare this to work properlyt =
new System.Threading.Thread(new System.Threading.ThreadStart(runningTimer));t.Start();
And you will be able to stop with with abort command. It's obsolete but works fine with me. And I couldn't learn another way yet.
t.Abort();
You can use a Void which I got and instead of writing the big code for delay at thread just call Delay and say the delay. Call it as Delay(number);
void Delay(int delayInMilliseconds)
{
System.Threading.Thread.Sleep(delayInMilliseconds);
}
private void runningTimer()
{
System.Net.WebRequest req = System.Net.WebRequest.Create(grate.ToString() + "?wsdl");
try
{
m_wr = req.GetResponse();
m_wr.Close();
}
catch{}
if (m_wr != null)
{
bconnected = true;
}
else
{
bconnected = false;
}
m_wr = null;
Delay(timer1.Interval); //Change this to the time that you want. Used delay of timer1 for now.
runningTimer();
}