线程中满足条件时如何操作

ssun1999 2007-04-03 12:25:24
public Thread t;

public void dd2()
{
t=new Thread(new ThreadStart(dd3));
t.Start();
t.Join(100);
}
public void dd3()
{
//处理事件。。。。。
if (s=="1")
{
this.Show();

}
}
当启动线程后处理事件满足条件后显示Form,
事件不满足时或错误食忽略。
...全文
209 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssun1999 2007-04-03
  • 打赏
  • 举报
回复
...........
ssun1999 2007-04-03
  • 打赏
  • 举报
回复
........
ssun1999 2007-04-03
  • 打赏
  • 举报
回复
这有关系码(和线程的优先级
zhangliu_521 2007-04-03
  • 打赏
  • 举报
回复
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(Thread1));
Thread t2 = new Thread(new ThreadStart(Thread2));

t1.Priority = ThreadPriority.BelowNormal ;
t2.Priority = ThreadPriority.Lowest ;
t1.Start();
t2.Start();
}
public static void Thread1()
{
for (int i = 1; i < 1000; i++)
{//每运行一个循环就写一个“1”
dosth();
Console.Write("1");
}
}
public static void Thread2()
{
for (int i = 0; i < 1000; i++)
{//每运行一个循环就写一个“2”
dosth();
Console.Write("2");
}
}
public static void dosth()
{//用来模拟复杂运算
for (int j = 0; j < 10000000; j++)
{
int a=15;
a = a*a*a*a;
}
}
以上程序运行结果为:

11111111111111111111111111111111111111111121111111111111111111111111111111111111111112

11111111111111111111111111111111111111111121111111111111111111111111111111111111111112

11111111111111111111111111111111111111111121111111111111111111111111111111111111111112

从以上结果我们可以看出,t1线程所占用CPU的时间远比t2的多,这是因为t1的优先级比t2的高,若我们把t1和t2的优先级都设为Normal,那结果是如何?它们所占用的CPU时间会一样吗?是的,正如你所料,见下图:

121211221212121212121212121212121212121212121212121212121212121212121

212121212121212121212121212121212121212121212121212121212121212121212

121212121212121212

ssun1999 2007-04-03
  • 打赏
  • 举报
回复
ding

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧