Debug.WriteLine很难

编程入门 行业动态 更新时间:2024-10-22 14:26:09
本文介绍了Debug.WriteLine很难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现了一个奇怪的问题,关于Debug.WriteLine和Thread在 暂停状态。 创建一个线程,启动它并使其暂停。 然后尝试Debug.WriteLine - 它将启动100%CPU使用率而不阻塞 主线程。 /> 代码如下(用两个按钮创建一个)。 步骤: 点击button1(启动并暂停线程)。然后点击button2。 你会注意到CPU的使用情况。天空。 只有当线程被暂停时才会出现这种情况。 Miha private void button1_Click(object sender,System.EventArgs e) { t = new Thread(新的ThreadStart(新的Tubo()。执行)); t.Name =" Tubo"; t.Start(); } private void button2_Click(object sender,System.EventArgs e) { //Debug.WriteLine(t.ThreadState); Debug.WriteLine("吐蕃); } } 公共课吐蕃 { public void执行() { 而(真) { Thread.CurrentThread.Suspend(); } } }

Hi, I''ve found a strange problem regarding Debug.WriteLine and Thread in suspended state. Create a thread, start it and make it suspended. Then try Debug.WriteLine - it will start 100% CPU usage while not blocking the main thread. Code is below (create a from with two buttons). Steps: Click on button1 (starts and suspends the thread). Then click on button2. You''ll note the CPU usage goes to sky. This only occurs if the thread is suspended. Miha private void button1_Click(object sender, System.EventArgs e) { t = new Thread(new ThreadStart(new Tubo().Execute)); t.Name = "Tubo"; t.Start(); } private void button2_Click(object sender, System.EventArgs e) { //Debug.WriteLine(t.ThreadState); Debug.WriteLine("Tubo"); } } public class Tubo { public void Execute() { while( true) { Thread.CurrentThread.Suspend(); } } }

推荐答案

不要使用Suspend(),使用同步机制。 Suspend()是问题,而不是Debug.WriteLine(),也许其他人可以 解释原因...... Don''t use Suspend(), use synchronization mechanisms. Suspend() is the problem, not Debug.WriteLine(), and maybe someone else can explain why...

不是。 CLR只会在他认为线程安全时暂停该线程这样做(参见MSDN中Thread.Suspend的描述)。 在您的代码中....看起来CLR认为挂起线程是不安全的,所以你无限期地循环消耗所有CPU 资源...... 而(true) { Thread.CurrentThread.Suspend( ); } 威利。 Miha Markic < MS ** @ spin.si>在留言新闻中写道:%2 ****************** @ TK2MSFTNGP11.phx.gbl ... No it is not. The CLR will only suspend the thread when HE considers it is safe to do so (see description of Thread.Suspend in MSDN). In your code.... it looks like the CLR considers it is not safe to suspend the thread so you loop indefinitely consuming all CPU resources... while( true) { Thread.CurrentThread.Suspend(); } Willy. "Miha Markic" <ms**@spin.si> wrote in message news:%2******************@TK2MSFTNGP11.phx.gbl... - Miha Markic - DXSquad Developer Express新闻组用于点对点支持。要获得Developer Express的直接支持,请写信至 su*****@devexpress 错误报告应直接发送至: su*****@devexpress 由于新闻组指南,DX- Squad不会回复匿名帖子。 pokémon < PO ** @ mon>在消息中写道新闻:m6 ************ @nwrdny03.gnilink ... Hi, Hmmm, is this only debug time problem? -- Miha Markic - DXSquad Developer Express newsgroups are for peer-to-peer support. For direct support from Developer Express, write to su*****@devexpress Bug reports should be directed to: su*****@devexpress Due to newsgroup guidelines, DX-Squad will not answer anonymous postings. "pokémon" <po**@mon> wrote in message news:m6************@nwrdny03.gnilink... 不要使用Suspend(),使用同步机制。 Suspend()是问题,而不是Debug.WriteLine(),也许别人 Don''t use Suspend(), use synchronization mechanisms. Suspend() is the problem, not Debug.WriteLine(), and maybe someone else

可以

解释原因... explain why...

" Miha Markic" < MS ** @ spin.si>在消息中写道 news:%2 ****************** @ TK2MSFTNGP11.phx.gbl ... "Miha Markic" <ms**@spin.si> wrote in message news:%2******************@TK2MSFTNGP11.phx.gbl... 嗯,这是唯一的调试时间问题吗? 看起来......我想知道它是否与听众或 $有关b $ b监听器锁定... - Miha Markic - DXSquad Developer Express新闻组用于点对点支持。要获得Developer Express的直接支持,请写 su*****@devexpress 错误报告应直接发送至: su ***** @ devexpress 由于新闻组的指导原则,DX-Squad不会回答匿名帖子。 神奇宝贝 < PO ** @ mon>在消息中写道新闻:m6 ************ @nwrdny03.gnilink ... Hi, Hmmm, is this only debug time problem? Appears to be... I wonder if its something to do with a listener or a listener lock... -- Miha Markic - DXSquad Developer Express newsgroups are for peer-to-peer support. For direct support from Developer Express, write to su*****@devexpress Bug reports should be directed to: su*****@devexpress Due to newsgroup guidelines, DX-Squad will not answer anonymous postings. "pokémon" <po**@mon> wrote in message news:m6************@nwrdny03.gnilink... 不要使用Suspend(),使用同步机制。 Suspend()是问题,而不是Debug.WriteLine(),也许别人 Don''t use Suspend(), use synchronization mechanisms. Suspend() is the problem, not Debug.WriteLine(), and maybe someone else

可以

解释原因... explain why...

更多推荐

Debug.WriteLine很难

本文发布于:2023-05-28 12:30:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:很难   Debug   WriteLine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!