I am developing an application which is written by c# + HTML + Java Script in the following structure: the base window is a WPF MainWindow class that opens a thread which creates a web page. This thread handles all the UI events.
The WebBrowser XAML code is:
<WebBrowser x:Name="CordovaBrowser"
Opacity="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Loaded="CordovaBrowser_Loaded"
Unloaded="CordovaBrowser_Unloaded"
LoadCompleted="CordovaBrowser_LoadCompleted"
/>
The problem is that I want to close the application from the HTML thread. I cannot use App.Current.ShutDown() because I'm not in the main UI thread (I've tried to do so but got an exception).
(BTW: For who knows PhoneGap: my application structure is very similar to how the Win8 PhoneGap is built.)
Can anyone please help me? Thanks.
What you want is (edited and taken from Application.Current.Shutdown() doesn't )
ThreadStart ts = delegate()
{
Dispatcher.BeginInvoke((Action)delegate()
{
Application.Current.Shutdown();
});
};
Thread t = new Thread(ts);
t.Start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.