附加到进程的自定义命令 [英] Custom command to attach to process
问题描述
嗨
我想要一个附加到流程的命令
I want to have a command to attach to a process
如果找不到流程我想要等待它变得可用。
If the process is not found I want to wait until it becomes available.
我使用Visual Commander编写命令并使其主要工作 - 除了一个问题。
I am using Visual Commander to write the command and have it mostly working - apart from one issue.
我运行命令Visual Studio IDE被冻结 - 这不是我想要的。
When I run the command the Visual Studio IDE is frozen - which is not what I want.
这是我的代码,请看一看,告诉我这是否可行。
Here is my code, please take a look and tell me if this is possible.
谢谢
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
int count = 10;
while(count-- > 0)
{
foreach(Process proc in DTE.Debugger.LocalProcesses)
{
if(proc.Name.ToString().EndsWith("MyProgram.exe"))
{
proc.Attach();
return;
}
}
System.Threading.Thread.Sleep(1000);
}
System.Windows.MessageBox.Show("Process running the Client Runtime was not found.");
}
}
推荐答案
Graham,
Graham,
您可以定期调用System.Windows.Forms.Application.DoEvents();使Visual Studio有点响应。
You can periodically call System.Windows.Forms.Application.DoEvents(); to make Visual Studio somewhat responsive.
更好的方法是启动计时器并对计时器刻度执行进程检查。它放在通用代码模块中肯定会工作,不确定常规命令。
扩展页面有几个计时器示例。
A better approach is to start a timer and perform the process check on a timer tick. It will certainly work when placed in a Common code module, not sure about a regular command. The Extensions page has several timer examples.
这篇关于附加到进程的自定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!