作者retrash ()
看板C_Sharp
标题[问题] 有关於 WaitOne 的使用
时间Mon Dec 10 10:36:25 2007
大家好
最近我想练习使用 WaitOne
所以写了个程式
程式里面会开另一个 thread 去 new 一个 form 出来,
然後原来的 thread 就 WaitOne
那个被新建出来的 form 上面有一个 buttom
按下那就会 Set()
可是....
那个 form 每次建到一半整个程式就荡掉了........
这是我的主程式
using System;
using System.Threading;
namespace test2
{
class MainClass
{
static private AutoResetEvent myWaker =
new AutoResetEvent(false);
static public Form1 myForm1;
public static void Main(string[] args)
{
Console.WriteLine("Start to call");
ThreadPool.QueueUserWorkItem(new WaitCallback(newWaker)
, myWaker);
if (myWaker.WaitOne(-1, false)) {
Console.WriteLine("get up");
}
else {
Console.WriteLine("oops");
}
Console.WriteLine("finish");
}
static void newWaker (object giveWaker) {
myForm1 = new Form1(giveWaker);
myForm1.Visible = true;
}
}
}
请当作我写的 form 是没问题的....因为那是 #Develop 写的........
谢谢指教 <(_ _)>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.224.38.172
※ 编辑: retrash 来自: 61.224.38.172 (12/10 10:36)
1F:推 deuter:WinForm程式要有message loop, 需要再加上 Application.Run 12/11 12:12
2F:→ retrash:谢谢 我待会试试 <(_ _)> 12/12 10:52