using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;namespace thread
{
class thread_run
{
public void run1()
{
Console.WriteLine("run 1");
}
public void run2()
{
Console.WriteLine("run 2");
}
public void run3()
{
Console.WriteLine("run 3");
}
}
class Program
{
static void Main(string[] args)
{
thread_run tr = new thread_run();
Thread th1 = new Thread(new ThreadStart(tr.run1));
th1.Priority = ThreadPriority.Normal;
th1.Start();
Thread th2 = new Thread(new ThreadStart(tr.run2));
th2.Priority = ThreadPriority.Highest;
th2.Start();
Thread th3 = new Thread(new ThreadStart(tr.run3));
th3.Priority = ThreadPriority.Lowest;
th3.Start();
Console.Read();
}
}
}
vs2005
编译运行按钮
出现输出是:
run2
run1
run3打开debug文件夹下面的编译出的exe
出现输出
run1
run2
run3用release 编译运行或者点文件直接运行结果都是
run2
run1
run3用shapdevelop
点三角运行结果
run2
run1
run3
点叹号运行
run1
run2
run3问题:
1,为什么会出现不同结果?
2,我比较倾向出现
run1
run2
run3
这个答案,但是另外的结果我就不明白了,程序不应该是顺序执行的吗?三个线程启动时间不同怎么会出现线程抢占呢?
新人发帖,请高手解答,,,
解决方案 »
- wince 6.0 , c# 编写 视频播放器
- 从数据库里查一个表。。用datatable类型的接收,CSV下载功能
- 安装程序在安装此程序包时遇到了错误。可能表明此程序包有错。错误代码是2869?在线等.....
- 郁闷,居然提示“使用了未赋值的局部变量”
- 读取xml到myDataTable
- xml 中节点和元素 的区别是什么啊
- 用程序异地备份sql server数据库的问题
- 怎样设置文本字背选中状态!
- 大家帮帮忙看看代码!为什么在下个页面得不到Session啊?
- 微软ComboBox的一个BUG?还是我的错误?
- 各位大侠,谁有过C#代码运行时间的跟踪工具,用来查找系统运行效率瓶颈问题,请支个招。
- DateTimePicker控件,我想替换下拉按钮的图标
using System.Collections.Generic;
using System.Text;
using System.Threading;namespace thread
{
class thread_run
{
public void run1()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("run 1");
}
}
public void run2()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("run 2");
}
}
public void run3()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("run 3");
}
}
}
class Program
{
static void Main(string[] args)
{
thread_run tr = new thread_run();
Thread th1 = new Thread(new ThreadStart(tr.run1));
th1.Priority = ThreadPriority.Normal;
Thread th2 = new Thread(new ThreadStart(tr.run2));
th2.Priority = ThreadPriority.Highest;
Thread th3 = new Thread(new ThreadStart(tr.run3));
th3.Priority = ThreadPriority.Lowest;
th1.Start();
th2.Start();
th3.Start();//《--
Console.Read();
}
}
}看这个程序,这样运行结果是一样的,但是如果吧有注释的那一行放到th1.Start();上面结果就不一样了,就是th2先出了