いくつかのオプションのコマンドライン引数を取ることができるWPFアプリケーションがあります。
このアプリケーションもシングルインスタンスアプリケーションです(インスタンスがすでに開いている場合は、ミューテックスを使用してインスタンスを閉じます)。
しかし、私が望んでいるのは、何かがいくつかのcmd行引数を使用してアプリケーションを開こうとした場合、アプリケーションはそれらを使用して想定されていることを実行することです(私のアプリケーションでは、cmd行に基づいて異なるダイアログを開きます)。
これを達成する最も簡単な方法は何ですか?
psedoコードでここに私が探しているものがあります
protected override void OnStartup(StartupEventArgs e)
{
bool mutexIsNew;
using (System.Threading.Mutex m =
new System.Threading.Mutex(true, "MyApplication", out mutexIsNew))
{
//if this is not the first instance of the app
if (!mutexIsNew)
{
//if there is some cmd line args
if (e.Args.Length > 0)
{
//send the args to the older instance so it can handle them
SendToOtherInstance(e.Args);
//shutdown this new instance
Application.Current.Shutdown();
}
}
}
base.OnStartup(e);
}