本文介绍了线程问题:睡眠线程变为自行停止。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在观察睡眠线程在一段时间后变为停止状态。 接受了Web应用程序的框架行为吗? 我的线程基本上做了一些工作,并且在打电话前睡了60分钟 本身是递归的,这意味着它应该按每小时运行小时。但它会在2小时后自动停止。我只收到2封电子邮件,每封送1封小时,然后什么都没有。当我在运行期间检查threadstate时,它已经从背景,waitsleepjoin变为停止了。我只是让 应用程序坐在那里,所以我知道后台没有其他任何事情发生。这是代码的。 //我在应用程序启动时手动启动线程 RateManager.GateKeeper worker = new RateManager.GateKeeper(" localhost",System.Configur ation.ConfigurationSetting s.AppSettings [&to; toEmail"],System.Configuration.ConfigurationSettings.AppSet ti ngs [" fromEmail"],GateKeeper正在初始化,GateKeeper Init); //保持全局句柄我可以在运行时检查线程行为 GlobalRateMan.GateKeeperMonitor = new Thread(新的ThreadStart (RateManager.GateKeeper.Analyze)); GlobalRateMan.GateKeeperMonitor.Priority = ThreadPriority.Lowest; GlobalRateMan.GateKeeperMonitor.Name =" GateKeeper"; GlobalRateMan.GateKeeperMonitor.IsBackground = true; GlobalRateMan.GateKeeperMonitor.Start(); // c将按钮上的文字改为暂停 - webding字体 GateKeeper.Text =" ;;" ;; GateKeeper.ToolTip = RateManager.GlobalRateMan.GateKeeperMonitor.Thread State.ToString(); //这里是分析 Email(); //通常的电子邮件代码 System.Threading.Thread.Sleep(TimeSpan.FromMinutes(Double.Parse(GlobalRateMa n.GateKeeperSleepTime))); // 60分钟 RateManager.GateKeeper.Subject =" GateKeeper准备运行分析 来自Netapp-1" ;; [snip] //工作在这里完成 //由睡眠时间控制的递归 分析(); 当我通过 GlobalRateMan.GateKeeperMonitor句柄检查线程的状态时这是一个静态句柄持有线程的 地址, 大约2小时后停止。在另一个相关的说明中,我注意到 其他奇怪的行为,如果这个线程从application_start事件启动后将拒绝发送电子邮件 。 解决方案 听起来你的递归有错。你能否制作一个 短但完整的例子来证明这个问题? - Jon Skeet - < sk * **@pobox.com> http://www.pobox.com/ 〜双向飞碟 如果回复小组,请不要给我发邮件 听起来你的递归有错。你能否制作一个简短但完整的例子来证明这个问题? - Jon Skeet - < sk *** @ pobox.com> http://www.pobox.com/~skeet 如果回复对于小组,请不要给我发邮件 I''m observing that a sleeping thread changes to stopped after a while. Isthat accepted framework behavior for web applications?My thread basically does some work, and sleeps for 60 minutes before callingitself recursively, which means it is supposed to run on the hour everyhour. But it automatically stops after 2 hours. I only get 2 emails, 1 perhour and then nothing. When I examine the threadstate during run-time, ithas changed from background, waitsleepjoin to stopped. I''m just letting theapp sit there so I know nothing else is going on in the background. Here''sthe code.//I manually start the thread when the application launchesRateManager.GateKeeper worker = newRateManager.GateKeeper("localhost",System.Configur ation.ConfigurationSettings.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet tings["fromEmail"],"GateKeeper is initializing","GateKeeper Init");//maintain a global handle so that i can examine thread behavior at runtimeGlobalRateMan.GateKeeperMonitor = new Thread (new ThreadStart(RateManager.GateKeeper.Analyze));GlobalRateMan.GateKeeperMonitor.Priority = ThreadPriority.Lowest;GlobalRateMan.GateKeeperMonitor.Name = "GateKeeper";GlobalRateMan.GateKeeperMonitor.IsBackground= true;GlobalRateMan.GateKeeperMonitor.Start();//change the text on the button to paused - webding fontGateKeeper.Text = ";";GateKeeper.ToolTip =RateManager.GlobalRateMan.GateKeeperMonitor.Thread State.ToString();//here is AnalyzeEmail(); //usual email codeSystem.Threading.Thread.Sleep(TimeSpan.FromMinutes (Double.Parse(GlobalRateMan.GateKeeperSleepTime))); //60 minutesRateManager.GateKeeper.Subject = "GateKeeper is preparing to run Analysisfrom Netapp-1";[snip]//work gets done here//recursion controlled by sleeptimeAnalyze();When I examine the state of the thread thru theGlobalRateMan.GateKeeperMonitor handle which is a static handle holding theaddress of the thread,it is stopped after about 2 hours. On another related note, I am noticingother weird behavior like this thread will refuse to email if it is startedfrom the application_start event. 解决方案It sounds like there''s a fault in your recursion. Could you produce ashort but complete example which demonstrates the problem?--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeetIf replying to the group, please do not mail me too It sounds like there''s a fault in your recursion. Could you produce a short but complete example which demonstrates the problem? -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too 这篇关于线程问题:睡眠线程变为自行停止。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 06:00
查看更多