It depends on the implementation of the process you want to stop, but you normally flag something on it that tells it you want it to stop.
class Program
{
static void Main(string[] args)
{
Worker w = new Worker();
Thread t = new Thread(new ThreadStart(w.DoWork));
t.Start();
Console.WriteLine("Press any key to stop");
Console.ReadKey();
Console.WriteLine("Stopping worker...");
w.Stopping = true;
t.Join();
Console.WriteLine("Worker stopped");
}
}
class Worker
{
public bool Stopping { get; set; }
public void DoWork()
{
while (!Stopping)
{
System.Diagnostics.Debug.WriteLine (DateTime.Now);
System.Threading.Thread.Sleep(1000);
}
}
}