class Program
{
public void Method1()
{
Console.WriteLine("Method1 is the starting point of excution of the thread");
}
static void Main(string[] args)
{
Program newclass=new Program(); // this class's name
Thread Thread1=new Thread(new ThreadStart(newclass.Method1));
Thread1.Start();
Console.WriteLine("The excution of Sample Thread has start.");
Thread1.Abort();
Console.ReadLine();
}
}
为什么执行结果是
the execution of Sample Thread has start
Mehtod1 is the starting point of excution of the threadThread1.Start();在前面啊????
解决方案 »
- 创建Access数据库,异常信息“没有注册类别”
- 一首很简单的计算题
- 想找一个互联网视频会议或授课软件,可以把自己的屏幕内容同时给远程的多个用户共享,有了解Microsoft office live meeting软件的兄弟吗
- C#中获取文本框的值的问题
- c#生成Word问题
- c#的套接字和vc的套接字之间可以通信么
- 呼叫 cutman (接分来了) 请帮忙解决在一副图片上画一个可以任意拉申控制大小的矩形问题(winform)
- 做个发邮件的webservice ,发送邮件失败
- C# 串口控件 Serial Port 全双工的使用问题,望请教
- DataAdapter.Update()与ADO.NET中的事务处理的疑问?
- 将年份信息添加的combobox下拉框
- 直接将BindingNavigator拖到窗体中,运行时为什么上面的按钮全呈灰色不可用状态?
加这一句试试
{
public void Method1()
{
Console.WriteLine("Method1 is the starting point of excution of the thread");
}
static void Main(string[] args)
{
Program newclass = new Program(); // this class's name
Thread Thread1 = new Thread(new ThreadStart(newclass.Method1));
Thread1.IsBackground = true;
Thread1.Start();
Console.WriteLine("The excution of Sample Thread has start.");
//Thread1.Abort();
Console.ReadLine();
}
}这样就是随机的了
将线程改为后台线程这个和线程执行顺序有关系?
你可以直接用Thread.Sleep()让某一个线程睡眠
还有你如果最近在学线程相关的知识,建议看一下<<C#线程手册>>,很不错的一本书加油
Thread1.start();//标识Thread1的线程启动,实际尚未开始工作,因为操作系统还没把CPU时间交给它
Console.WriteLine("The excution of Sample Thread has start.");//主线程时间片未释放继续运行
时间片1结束时间片2(Thread1占据)
Method1();//轮到Thread1使用CPU时间因为每次分得的时间片大小一致,所有时间上能完成语句行数也一致,所以结果一致使用了线程就不能按照代码顺序判断执行的先后了