【发布时间】:2011-01-20 14:13:36
【问题描述】:
从我读到的关于这个 .Join() 的内容来看,它似乎要等待相关线程完成其操作,然后再加入并继续执行主代码。但是,据我所知,当我的代码卡在 .Join() 上时,该线程不再运行并且似乎已经关闭。在有问题的线程上命中的最后一行代码是 this.Close()。任何想法正在发生什么以及如何解决它?
这是一个在 Windows CE 手持设备上运行的 C# 可执行程序。
我可能还应该补充一点,这是一个间歇性问题,不会一直发生。
这是线程开始:
//Start the thread to continuously receive while the LP dialog is open
Thread Form2Thread = new Thread(new ThreadStart(this.Nep450_ThreadLowPower));
这是 .Join() 之前的代码:
else if (Form2.g_IsOKPressed)//This variable is set in the thread in qustionFomr
{
g_bThreadLowPowerTerminate = true;
Thread.Sleep(500);
Form2Thread.Join();
我找到了问题的根源。当第二次运行代码时,以下行被命中并导致问题。删除后就没有问题了。
this.Invoke(new EventHandler(CloseLPDialog));
【问题讨论】:
-
一个代码示例会很有帮助。如果您可以向我们展示您的主线程的一部分(创建和启动线程以及执行
Join的部分),我们也许能够发现问题。
标签: c# .net multithreading visual-studio-2005 windows-ce