C# 2010 System.Runtime.InteropServices, How to Detect Running Processes?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I tried in a previous post to add some error handling to my project, which hosts IE or Firefox inside of a panel on a form. Sadly it only covers part of the problem.
[DllImport("user32.dll", SetLastError = true)]<br/>
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
button_click(etc)
{
//Process p = Process.Start("iexplore.exe");<br/>
//Thread.Sleep(900);<br/>
//p.StartInfo.CreateNoWindow = true;<br/>
//SetParent(p.MainWindowHandle, panel1.Handle);<br/>
//p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
}
For the sake of user-friendliness, Id like to have the thing detect when the process is running, so that it disables the button that code is in until you close the browser. If I click the button while IE is running, it crashes out. I cant figure
out the basic commands for "if(running) {button.enabled = false} else{button.enabled = true;}" and the other side of that to close it, if(running){process.kill} else{do nothing}; Not fantastic with interop so Im not having much luck adding mods to the
existing Process class.
Any ideas on how to fix this one? Thanks in advance! <hr class="sig May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!

View the full article
 
Back
Top