私はいくつかのオプションのコマンドライン引数を取ることができるWPFアプリケーションを持っています。2つのアプリケーション間の単純な通信
このアプリケーションも単一インスタンスのアプリケーションです(すでに開いている場合は、すべてのインスタンスを閉じるためにミューテックスを使用します)。
何かしたいのですが、何かcmd行のargsでアプリケーションを開こうとすると、アプリケーションはそれらのアプリケーションと何をするのでしょうか?(私のアプリケーションでは、 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);
}
メッセージ転送のためにメモリマップファイルを使用して待機ハンドルを使用することができます - この記事のようにhttp://techmikael.blogspot.com/2010/02/blazing-fast-ipc-in-net-4 -wcf-versushtml –
簡単な方法は、このログインをアプリの 'Main()'メソッドに入れることです。あなたがそれをやることを妨げる何かがありますか? –