両方のexeを使用して2つのexeを並列で実行しよParallel.Invoke()
うとしていますが、同じデータベース(ただし異なるテーブル)にアクセスしようとしています。また、exeは2つの異なるサーバーで実行されます。C#でWMIを使用して、リモートサーバーでバッチファイル(他のexeファイルを呼び出す)を開始しています。
Parallel.Invoke(() =>
{
RunInParallel();
},
() =>
{
InvokeModule("EmiCalculator.exe");
}
);
void RunInParallel()
{
var connoptions = new ConnectionOptions();
var managementScope = new ManagementScope
(String.Format(@"\\{0}\ROOT\CIMV2", REMOTE_COMPUTER), connoptions);
var wmiProc = new ManagementClass(managementScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
string commandLineInput = @"\\win-server1\D$\Data\Run.bat";
var processToRun = new[] { commandLineInput };
wmiProc.InvokeMethod("Create", processToRun);
}
Run.batはSalaryCalculator.exeを呼び出しています
両方のexeには、以下のようにConnectionStringを含む構成ファイルがあります。
<add name="CONN" connectionString="Data Source=SERVER1-LAB1;Initial Catalog=Loan;Integrated Security=True"/>
実行中、リモートマシンのexeがクラッシュし、例外を下回っています:
Application: SalaryCalculator.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AggregateException
Stack:
at System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[], Int32, System.Threading.CancellationToken)
at System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[], Int32)
at System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[])
注:リモートマシンに接続した後にバッチファイルを実行すると、完全に機能しています。で使用した場合にのみエラーがスローされますParallel.Invoke()
どうすればここに進むことができますか?どんな助けでも大歓迎です。