C# でアプリケーションを開発しました。ユーザーがアプリケーションのタスク マネージャーでプロセスを強制終了した場合、アプリケーションが自動的に再起動する方法はありますか
2766 次
2 に答える
3
私が見る唯一の解決策は、プライマリプロセスを監視して再起動する別のプロセスです。プライマリ プロセスで Mutex を使用し、監視プロセスでその Mutex を監視します。Released Mutex は、プライマリ プロセスが停止したことを意味します。
/// <summary>
/// Main Program.
/// </summary>
class Program
{
static void Main(string[] args)
{
// Create a Mutex which so the watcher Process
using (var StartStopHandle = new Mutex(true, "MyApplication.exe"))
{
// Start the Watch process here.
Process.Start("MyWatchApplication.exe");
// Your Program Code...
}
}
}
監視プロセス:
/// <summary>
/// Watching Process to restart the application.
/// </summary>
class Programm
{
static void Main(string[] args)
{
// Create a Mutex which so the watcher Process
using (var StartStopHandle = new Mutex(true, "MyApplication.exe"))
{
// Try to get Mutex ownership.
if (StartStopHandle.WaitOne())
{
// Start the Watch process here
Process.Start("MyApplication.exe");
// Quit after starting the Application.
}
}
}
}
于 2013-04-30T10:15:48.607 に答える