you can use Application.Current.Shutdown() to stop your application. This can appended before Window shown if it is call in the OnStartup.
For reading arguments, you can use e.Args in OnStartup or Environment.GetCommandLineArgs() everywhere.
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// check if it is the first instance or not
// do logic
// get arguments
var cmdLineArgs = e.Args;
if (thisisnotthefirst)
{
// logic interprocess
// do logic
// exit this instance
Application.Current.Shutdown();
return;
}
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
// may be some release needed for your single instance check
base.OnExit(e);
}
}
I don't know how you check the single instance, but i use Mutex for that :
protected override void OnStartup(StartupEventArgs e)
{
Boolean createdNew;
this.instanceMutex = new Mutex(true, "MySingleApplication", out createdNew);
if (!createdNew)
{
this.instanceMutex = null;
Application.Current.Shutdown();
return;
}
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
if (this.instanceMutex != null)
{
this.instanceMutex.ReleaseMutex();
}
base.OnExit(e);
}
Hop that will help you.