Hi I want to pass sleeptime and the Thread Object to a method and call the method in a for loop. Pls see the code below
public delegate void PasParamsToThrdFunc(int integer, object obj2);
class Program
{
Thread[] newThread=new Thread[10];
static void Main(string[] args)
{
Program pr = new Program();
pr.ThreadDeclaration();
Console.Read();
}
public void ThreadDeclaration()
{
int time = 5000;
for(int i=1;i<3;i++)
{
time = time * i;
string s = i.ToString();
ThreadStart starter = () => PasParamsToThrdFunc(time, newThread[i]);
newThread[i] = new Thread(starter);
newThread[i].Name = i.ToString();
newThread[i].Start();
}
}
public void PasParamsToThrdFunc(int waitTime, Thread obj)
{
Thread.Sleep(waitTime);
Console.WriteLine("" + waitTime + " seconds completed and method is called for thread"+obj.Name+"");
obj.Abort();
}
}
I want the 1st thread to be invoked after 5 seconds and shall kill the object and shall do the same for the 2nd thread and kill it at 10 seconds. Please help... Thanks in advance.