I am using an XBAP application in full trust. I need to close the browser hosting the XBAP when I click a button. How can I achieve this? Application.Currenty.ShutDown()
only closes the application, leaving the browser blank.
Asked
Active
Viewed 3,415 times
5

Svetlozar Angelov
- 21,214
- 6
- 62
- 67

ARV
- 1,111
- 5
- 22
- 46
-
1+1 to compensate for the unfair -1... that's a good question – Thomas Levesque Aug 31 '09 at 14:23
3 Answers
5
I know this is a really old question, but in case anyone has this issue, here's a simpler solution that will close just the one tab.
Environment.Exit(0);
Source: Microsoft Forums

Dan
- 1,222
- 2
- 17
- 33
4
EDIT: My mistake, here is a thread with your problem - http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21c88fed-c84c-47c1-9012-7c76972e8c1c
and to be more specific (this code needs full trust security settings)
using System.Windows.Interop;
using System.Runtime.InteropServices;
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Auto)]
private static extern IntPtr GetAncestor(IntPtr hwnd, int flags);
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
private void button1_Click(object sender, RoutedEventArgs e)
{
WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow);
IntPtr ieHwnd = GetAncestor(wih.Handle, 2);
PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero);
}

Svetlozar Angelov
- 21,214
- 6
- 62
- 67
-
I was not able to find HtmlPage in xbap project, tryed to refere system.windows.browser namespace chould not find it. – ARV Aug 31 '09 at 13:04
-
It is more usefull that is sounds to be: A colleague of me needs to prevent several instances of a XBAP application to be launched. Closing the faulty new instance using this method saved his life :) Thanks. – Larry Sep 10 '09 at 13:57
1
This is great!, however it also shuts down all of IE, including any open tabs
Your not going to believe this one, but if you also do a Application.Current.Shutdown(): after above it aborts the total IE shutdown and just shuts the applications tab.
private void exitButton_Click(object sender, RoutedEventArgs e)
{
// This will Shut entire IE down
WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow);
IntPtr ieHwnd = GetAncestor(wih.Handle, 2);
PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero);
// Singularly will just shutdown single tab and leave white screen, however with above aborts the total IE shutdown
// and just shuts the current tab
Application.Current.Shutdown();
}

PrimeTSS
- 2,683
- 3
- 23
- 26