For Programmers: Free Programming Magazines  


Home > Archive > C# > June 2006 > Application.Exit() not working









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Application.Exit() not working
lbolognini@gmail.com

2006-06-24, 8:15 am

Hi all,

got this code inside a Windows Form 1.1 that opens a file with Notepad:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.FileName = "Notepad";
proc.StartInfo.Arguments =
" C:\\WINDOWS\\system32\\drivers\\etc\\hos
ts";
proc.Start();
if (proc.HasExited == true)
{
//why doesn't this work?
Application.Exit();
}

Why isn't the application exiting when I close Notepad? How do i make
it behave like that?

Thanks,
Lorenzo

Josh Twist

2006-06-28, 8:03 am

private void Foo()
{
Process proc = new Process();
proc.StartInfo.FileName = "Notepad";
proc.StartInfo.Arguments =
" C:\\WINDOWS\\system32\\drivers\\etc\\hos
ts";
proc.EnableRaisingEvents = true;
// wire up an event handler
proc.Exit += new EventHandler(proc_Exit);
}

private void proc_Exit()
{
Application.Exit();
}

lbolognini@gmail.com wrote:
> Hi all,
>
> got this code inside a Windows Form 1.1 that opens a file with Notepad:
>
> System.Diagnostics.Process proc = new System.Diagnostics.Process();
> proc.EnableRaisingEvents = true;
> proc.StartInfo.FileName = "Notepad";
> proc.StartInfo.Arguments =
> " C:\\WINDOWS\\system32\\drivers\\etc\\hos
ts";
> proc.Start();
> if (proc.HasExited == true)
> {
> //why doesn't this work?
> Application.Exit();
> }
>
> Why isn't the application exiting when I close Notepad? How do i make
> it behave like that?
>
> Thanks,
> Lorenzo


lbolognini@gmail.com

2006-06-29, 4:00 am


Josh Twist wrote:

> // wire up an event handler
> proc.Exit += new EventHandler(proc_Exit);
> }
>
> private void proc_Exit()
> {
> Application.Exit();
> }



Thanks Josh,
Lorenzo

Josh Twist

2006-06-29, 8:00 am

No Probs.

Josh
http://www.thejoyofcode.com/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com