I start to learn about threading and I wrote this code.
static void Main(string[] args)
{
Thread DoAction = new Thread(StartAction);
DoAction.Start();
for (int i = 0; i < 10000000; i++)
{
Console.WriteLine("Main Thread: {0}", i);
if (i == 10000) DoAction.Suspend();
}
}
static void StartAction()
{
for(int i=0;i<int.MaxValue;++i)
{
Console.WriteLine(i);
}
}
When i==10000 my application stopped. I want to suspend only DoAction Thread
Console is a 'thread-safe' class meaning that acces is regulated internally with locks.
With a little (bad) luck you will suspend the worker thread in the middle of a WriteLine().
Your main thread is then put on hold when it tries to write, and you're deadlocked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With