I have an application that launches another application from my project:
MainWindow mw = new OtherApplication.MainWindow();
mw.Show();
When this other application is closed, it also automatically terminates the parent application. This is what I try to avoid. I use this method to close the child application:
private void btnClose_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
The subordinate application can either be used independently or it is called by the parent application. Can I somehow determine whether the application was started alone or whether it runs as a child process of the parent application? In this case, I would probably have to adjust the btnClose_Click method?
How can I close the appliactions running as a child process without terminating the parent application?
I found out for myself:
private void btnClose_Click(object sender, RoutedEventArgs e)
{
string processname = System.IO.Path.GetFileNameWithoutExtension
(System.Reflection.Assembly.GetEntryAssembly().Location);
if (processname != "OtherApplicationName")
Close();
else
Application.Current.Shutdown();
}
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.