I have written a very simple application that simply spawns IE then closes
it. The issue I have is that CloseMainWindow() always returns a false
indicating the message was never sent. Does someone know why?
This application is nothing more than a form with a button. The button's
code below spawns IE.
private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < 2; i++)
{
System.Diagnostics.Process spawned = new Process();
spawned.StartInfo.FileName = "IEXPLORE.EXE";
spawned.StartInfo.UseShellExecute = true;
spawned.StartInfo.Arguments = "http://WWW.MSN.COM";
spawned.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
try
{
spawned.Start();
if (spawned.Responding)
{
int count = 0;
while (!spawned.HasExited)
{
if (spawned.CloseMainWindow())
Console.WriteLine("Exit message sent:" +
count++);
else
Console.WriteLine("Exit message was not
sent: " + count++);
Thread.Sleep(2000);
}
spawned.WaitForExit();
int exitCode = spawned.ExitCode;
Console.WriteLine("exit code: " + exitCode);
spawned.Close();
}
}
catch (Exception L2)
{
string s = String.Format("{0}\n{1}\nL2", L2.Message,
L2.StackTrace);
Console.WriteLine(s);
}
}
}
catch (Exception L1)
{
string s = String.Format("{0}\n{1}\nL1", L1.Message,
L1.StackTrace);
Console.WriteLine(s);
}
}
--
-----------
Thanks,
Steve