none
Custom command to attach to process

    Question

  • Hi 

    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.

    I am using Visual Commander to write the command and have it mostly working - apart from one issue.

    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.

    Thanks

    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.");
    	}
    }	
    

    Friday, October 26, 2018 10:54 AM

All replies