Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

How to close the app from anywhere in the app?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 08-07-2007   #1 (permalink)
Richard Lewis Haggard
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
close with the X means close, not minimze to the system tray Destin_FL Live Mail 3 07-27-2008 10:03 AM
Close Tabs Closes Everything! I don't want to Close Everything! Robbia Vista mail 1 04-07-2008 11:42 AM
cannot close windows media player when i click the 'close' button yulung Vista music pictures video 2 12-24-2007 04:37 PM
Close this program or search for the right topic and close this pr Allan Vista security 0 07-18-2007 07:28 AM
It's getting close... Travis King Vista General 14 05-22-2006 08:48 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51