What is the best way to handle a thread from a different thread?

  • Thread starter Thread starter Madan Mishra
  • Start date Start date
M

Madan Mishra

Guest
My requirement is to handle a thread from a different thread. I am able to do with thread.Suspend(), thread.Resume() and thread.Abort() but I am getting a warning like these methods has been deprecated. Is there any alternative to these methods, I created a dummy console application which is similar to my application. in actual application there is no loop used. its number of steps to execute and every step will call to a different assembly code. please help to to fix this. Below is my code.


using System;
using System.Threading;

namespace ThreadingTest
{
internal class Program
{
private static Thread mainThread;

private static void Main(string[] args)
{
mainThread = Thread.CurrentThread;

Thread connectServerThread = new Thread(new ThreadStart(ConnectServer));
connectServerThread.Start();

int i = 0;
while (true)
{
if (i++ % 5000 == 0)
{
Console.WriteLine(i);
}
}
}

private static void ConnectServer()
{
for (int i = 0; i < 20; i++)
{
Thread.Sleep(2000);
if (i % 2 == 0)
{
mainThread.Suspend();
}
else
{
mainThread.Resume();
}
}
mainThread.Abort();
}
}
}

Continue reading...
 
Back
Top