M
Miha Markic
Hi,
I've found a strange problem regarding Debug.WriteLine and Thread in
suspended state.
Create a thread, start it and make it suspended.
Then try Debug.WriteLine - it will start 100% CPU usage while not blocking
the main thread.
Code is below (create a from with two buttons).
Steps:
Click on button1 (starts and suspends the thread). Then click on button2.
You'll note the CPU usage goes to sky.
This only occurs if the thread is suspended.
Miha
private void button1_Click(object sender, System.EventArgs e)
{
t = new Thread(new ThreadStart(new Tubo().Execute));
t.Name = "Tubo";
t.Start();
}
private void button2_Click(object sender, System.EventArgs e)
{
//Debug.WriteLine(t.ThreadState);
Debug.WriteLine("Tubo");
}
}
public class Tubo
{
public void Execute()
{
while( true)
{
Thread.CurrentThread.Suspend();
}
}
}
I've found a strange problem regarding Debug.WriteLine and Thread in
suspended state.
Create a thread, start it and make it suspended.
Then try Debug.WriteLine - it will start 100% CPU usage while not blocking
the main thread.
Code is below (create a from with two buttons).
Steps:
Click on button1 (starts and suspends the thread). Then click on button2.
You'll note the CPU usage goes to sky.
This only occurs if the thread is suspended.
Miha
private void button1_Click(object sender, System.EventArgs e)
{
t = new Thread(new ThreadStart(new Tubo().Execute));
t.Name = "Tubo";
t.Start();
}
private void button2_Click(object sender, System.EventArgs e)
{
//Debug.WriteLine(t.ThreadState);
Debug.WriteLine("Tubo");
}
}
public class Tubo
{
public void Execute()
{
while( true)
{
Thread.CurrentThread.Suspend();
}
}
}