public void Exec(Guid pguidCmdGroup, uint nCmdID, OLECMDEXECOPT nCmdexecopt, ref object pvaIn, ref object pvaOut) { if (nCmdID == 0) { using (Process p = Process.GetCurrentProcess()) pvaOut = p.Id; } else if (nCmdID == 1) { // WinLive 198331 // We could be on an MTA thread at this point, but action here involves writer UI // and we need an STA compliant thread for it. We will spin up a new thread here // which is explicitly set to STA and launch our action through it. LaunchActionThreadWithState launchAction = new LaunchActionThreadWithState(_action, pvaIn as string[]); Thread staThread = new Thread(new ThreadStart(launchAction.ThreadProc)); // Set to STA model staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); // Wait for the new thread to finish while pumping any COM messages staThread.Join(); // Grab the return value pvaOut = launchAction.ReturnValue; } }
public void Exec(Guid pguidCmdGroup, uint nCmdID, OLECMDEXECOPT nCmdexecopt, ref object pvaIn, ref object pvaOut) { if (nCmdID == 0) { using (Process p = Process.GetCurrentProcess()) pvaOut = p.Id; } else if (nCmdID == 1) { // WinLive 198331 // We could be on an MTA thread at this point, but action here involves writer UI // and we need an STA compliant thread for it. We will spin up a new thread here // which is explicitly set to STA and launch our action through it. LaunchActionThreadWithState launchAction = new LaunchActionThreadWithState(_action, pvaIn as string[]); Thread staThread = new Thread(new ThreadStart(launchAction.ThreadProc)); // Set to STA model staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); // Wait for the new thread to finish while pumping any COM messages staThread.Join(); // Grab the return value pvaOut = launchAction.ReturnValue; } }