C# で小さなプログラムを作成しました。このプログラムはクルーズ コントロールに統合されます (編集: おっと、Enter キーを押すのが早すぎます)。これは、特定の (事前定義されていない) JVM を独自の個別のスレッドで作成します。ただし、スレッドを強制終了すると、JVM はまだ存在し、アンロードされません。この機能は .bat ファイルで正しく動作しますが、JVM を呼び出すと、まだ開いたままになります!
各スレッドは、このクラスのインスタンスから作成され、Run() を呼び出します。
_Critical は、テストの目的でメイン プロセスによって使用されます。
class BatThread
{
private string _args, _fileName;
private bool _critical;
public ManualResetEvent Flag;
public BatThread(string fileName, string args, bool critical)
{
_fileName = fileName;
_args = args;
_critical = critical;
Flag = new ManualResetEvent(false);
}
public void Run()
{
using (Process Proc = new Process())
{
Proc.StartInfo.FileName = _fileName;
Proc.StartInfo.Arguments = _args;
Proc.StartInfo.RedirectStandardError = false;
Proc.StartInfo.RedirectStandardInput = false;
Proc.StartInfo.RedirectStandardOutput = false;
Proc.StartInfo.UseShellExecute = true;
Proc.Start();
while (true)
{
if (Proc.WaitForExit(100))
{
break;
}
else if (this.Flag.WaitOne(100))
{
Proc.Kill();
break;
}
Thread.Sleep(5000);
}
this.Flag.Set();
}
}
public bool critical { get { return _critical; } }
}