Visual Studio立即窗口生成任务和线程阻塞问题 [英] Visual Studio Immediate Window Spawning Tasks and Threads blocking issue

查看:79
本文介绍了Visual Studio立即窗口生成任务和线程阻塞问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用特定工具来检查我的应用程序.一旦应用程序遇到断点,我就可以通过调用某个函数从即时窗口"中调用我的工具.该工具本身是一个多线程Windows应用程序,因此产生了一些任务.

I use a specific tool to inspect my app. Once the app hits a breakpoint I can invoke my tool from the Immediate Window by calling a certain function. The tool itself is a multi-threaded Windows App and therefore spawns some tasks.

我面临的问题是,有时从该工具安排的某些任务永远不会运行,这会导致我的工具无限期地挂起.我使用 ThreadPool.QueueUserWorkItem Task.Run 生成任务,它们都会导致工具挂起并且从不执​​行这些任务.如果我使用 Thread 类,则该工具可以完美运行.

The problem that I am facing is that sometimes some tasks scheduled from the tool are never run which causes my tool to hang indefinitely. I spawn tasks with ThreadPool.QueueUserWorkItem or with Task.Run and they both cause the tool to hang and never execute these tasks. If I use Thread class instead the tool works perfectly.

此外,如果正常启动(即不是从即时窗口"启动),该工具也可以(与任务"一起使用).因此,仅当我使用任务和立即"窗口时,才会出现此问题.

Also, the tool works (with Tasks) if started normally i.e. not from the Immediate Window. Therefore the problem occurs only if I use Tasks and Immediate window.

因此,我的问题是某些任务从未执行的原因可能是什么?我了解即时窗口会阻止所有其他线程并在到达断点的线程上执行命令,但是从即时窗口线程产生的线程/任务仍应执行,对吗?

Thus, my question is what might be the reason that some tasks are never executed? I understand that Immediate Window blocks all other threads and executes the command on the thread which hit the breakpoint, but the threads/tasks spawned from the Immediate Window thread should be still executed, right?

我的应用程序和工具都在C#中.我正在使用Visual Studio Professional 2015 Update 1.

Both my app and the tool are in C#. I am using Visual Studio Professional 2015 Update 1.

推荐答案

与分步调试相反,即时窗口一次仅执行单个线程-主线程或当前线程.它无法调用新线程或任务.因此,您的工具将卡住.

Immediate window, in contrast to step-by-step debugging, does only execute asingle thread at a time - the main or the current thread. It Cannot invoke new threads or tasks. Therefore your tool will stuck.

这篇关于Visual Studio立即窗口生成任务和线程阻塞问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆