Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to close the app from anywhere in the app?

 
 
Old 08-07-2007   #1 (permalink)
Richard Lewis Haggard


 
 

How to close the app from anywhere in the app?

How can an application be closed from a location other than the ShellWIndow?
In this case, File->Exit's command handler is in a class derived from
IApplicationView and it needs to close the application. How can this be
done?
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm



My System SpecsSystem Spec
Old 08-07-2007   #2 (permalink)
Lloyd Dupont


 
 

Re: How to close the app from anywhere in the app?

> How can an application be closed from a location other than the
> ShellWIndow? In this case, File->Exit's command handler is in a class
> derived from IApplicationView and it needs to close the application. How
> can this be done?


From Application.Run() documentation:
"An application stops running when Shutdown is called;"

Hence I suggest: Application.Current.Shutdown()

> --
> Richard Lewis Haggard
> General: www.Haggard-And-Associates.com
> Please come visit here for a couple thousand good giggles!:
> www.haggard-and-associates.com/Humor/humor.htm
>
>


My System SpecsSystem Spec
Old 08-08-2007   #3 (permalink)
Richard Lewis Haggard


 
 

Re: How to close the app from anywhere in the app?

Environment.Exit(0); seems to work. Application did not offer me the options
of Current.Shutdown();
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

"Lloyd Dupont" <net.galador@ld> wrote in message
news:e05NxxV2HHA.5796@TK2MSFTNGP05.phx.gbl...
>> How can an application be closed from a location other than the
>> ShellWIndow? In this case, File->Exit's command handler is in a class
>> derived from IApplicationView and it needs to close the application. How
>> can this be done?

>
> From Application.Run() documentation:
> "An application stops running when Shutdown is called;"
>
> Hence I suggest: Application.Current.Shutdown()
>
>> --
>> Richard Lewis Haggard
>> General: www.Haggard-And-Associates.com
>> Please come visit here for a couple thousand good giggles!:
>> www.haggard-and-associates.com/Humor/humor.htm
>>
>>

>



My System SpecsSystem Spec
Old 08-09-2007   #4 (permalink)
StanB


 
 

Re: How to close the app from anywhere in the app?

I just did Close():

public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
}

void OnExit (object sender, RoutedEventArgs e)
{
Close();
}
}

"Lloyd Dupont" <net.galador@ld> wrote in message
news:e05NxxV2HHA.5796@TK2MSFTNGP05.phx.gbl...
>> How can an application be closed from a location other than the
>> ShellWIndow? In this case, File->Exit's command handler is in a class
>> derived from IApplicationView and it needs to close the application. How
>> can this be done?

>
> From Application.Run() documentation:
> "An application stops running when Shutdown is called;"
>
> Hence I suggest: Application.Current.Shutdown()
>
>> --
>> Richard Lewis Haggard
>> General: www.Haggard-And-Associates.com
>> Please come visit here for a couple thousand good giggles!:
>> www.haggard-and-associates.com/Humor/humor.htm
>>
>>

>



My System SpecsSystem Spec
Old 08-10-2007   #5 (permalink)
Richard Lewis Haggard


 
 

Re: How to close the app from anywhere in the app?

Indeed, this works fine from within the Window derived class. However, the
question predicated that the close may be called from anywhere within the
application, not just within the main window. I'd originally thought that
there would be some easy way to get hold of the main window but was unable
to find such functionality. In the end, I found a work around so the
question is now mute. Thanks anyway.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

"StanB" <stan@community.nospam.com> wrote in message
news:e%23yCMAo2HHA.1204@TK2MSFTNGP03.phx.gbl...
>I just did Close():
>
> public partial class MainWindow : System.Windows.Window
> {
> public MainWindow()
> {
> InitializeComponent();
> }
>
> void OnExit (object sender, RoutedEventArgs e)
> {
> Close();
> }
> }
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:e05NxxV2HHA.5796@TK2MSFTNGP05.phx.gbl...
>>> How can an application be closed from a location other than the
>>> ShellWIndow? In this case, File->Exit's command handler is in a class
>>> derived from IApplicationView and it needs to close the application. How
>>> can this be done?

>>
>> From Application.Run() documentation:
>> "An application stops running when Shutdown is called;"
>>
>> Hence I suggest: Application.Current.Shutdown()
>>
>>> --
>>> Richard Lewis Haggard
>>> General: www.Haggard-And-Associates.com
>>> Please come visit here for a couple thousand good giggles!:
>>> www.haggard-and-associates.com/Humor/humor.htm
>>>
>>>

>>

>
>



My System SpecsSystem Spec
Old 08-12-2007   #6 (permalink)
Lloyd Dupont


 
 

Re: How to close the app from anywhere in the app?

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom> wrote in message
news:eUNWxL22HHA.5240@TK2MSFTNGP02.phx.gbl...
> Environment.Exit(0); seems to work. Application did not offer me the
> options of Current.Shutdown();
> --

Didn't it?
Are you sure you are writting a "standart" WPF application?
That is one with:
public partial class App : System.Windows.Application

Because, here are some snippets from System.Windows.Application
documentation:

public static Application Current { get; }
public void Shutdown ()


Anyway, good that you found a method to do it.
I'm just curious to know if we talked about the same thing....

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Have to press 'Close' or 'X' twice to close Windows Explorer windo Vista General
cannot close windows media player when i click the 'close' button Vista music pictures video
close with the X means close, not minimze to the system tray Live Mail
Close Tabs Closes Everything! I don't want to Close Everything! Vista mail
Close this program or search for the right topic and close this pr Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46