请教一个有关线程的问题
请教一个有关线程的问题,我以前没有用过线程,看MSDN上的控制台例子,发现用断点跟踪和直接运行的结果不一样。搞不清线程到底是如何运行的。我的代码是:
using System;
using System.Threading;
namespace ThreadTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.Write("Start\n");
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
for(int i = 0 ;i < 4 ;i++)
{
Console.Write("times:{0}\n",i);
Thread.Sleep(0);
}
Console.Write("pauze\n");
Console.Write("continue\n");
t.Join();
Console.Write("done\n");
Console.ReadLine();
}
public static void ThreadProc()
{
for(int j = 0 ;j < 10 ; j++)
{
Console.Write("ThreadProc{0}\n",j);
Thread.Sleep(0);
}
}
public static void ThreadOption()
{
Console.Write("Option\n");
}
}
}
using System.Threading;
namespace ThreadTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.Write("Start\n");
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
for(int i = 0 ;i < 4 ;i++)
{
Console.Write("times:{0}\n",i);
Thread.Sleep(0);
}
Console.Write("pauze\n");
Console.Write("continue\n");
t.Join();
Console.Write("done\n");
Console.ReadLine();
}
public static void ThreadProc()
{
for(int j = 0 ;j < 10 ; j++)
{
Console.Write("ThreadProc{0}\n",j);
Thread.Sleep(0);
}
}
public static void ThreadOption()
{
Console.Write("Option\n");
}
}
}