I have an WPF application called app1 which has a windows named window1. When the user clicks the close button of window1, the app does not close but the window1 hides (this.hide()).
I want to check if another instance of the application is already running when it is started; if so, I want to show the already running instance and terminate the new one.
How can I do that?
I know how to check the process and how to close the current app but I don’t know how to show a window from another WPF process which is running…
In my App startup event I do this :
private void Application_Startup(object sender, StartupEventArgs e)
{
if(Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Count() > 1)
{
Application.Current.Shutdown(0);
}
}
I found how to do the work!
My problem solved with “Reed Copsey” help and with Windows SendMessage API.
for doing this thing I wrote these codes in my window1.xaml.cs file :
And I wrote these codes in my App.xaml.cs :
And that’s it. 😀