【问题标题】:System.AggregateException exception when using with Parallel.Invoke()与 Parallel.Invoke() 一起使用时出现 System.AggregateException 异常
【发布时间】:2013-02-06 16:26:12
【问题描述】:

我正在尝试使用 Parallel.Invoke() 并行运行 2 个 exe 这两个 exe 都试图访问同一个数据库(但不同的表)。此外,exe 将在两个不同的服务器中运行。 我正在使用带有 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()一起使用时只会抛出错误

我该如何继续?任何帮助表示赞赏。

【问题讨论】:

  • 感谢@Aron 的评论。但是,我能够完成这项工作。请在下面找到我的答案。

标签: c# parallel-processing wmi


【解决方案1】:

我能够完成这项工作。问题是连接字符串,因为提到了集成安全。 我只是将连接字符串更改为使用 SQL server authentication 而不是 Windows 身份验证。而且效果很好。

< add name="CONN" connectionString="Data Source=SERVER1-LAB1;Initial Catalog=Loan;User Id=sa;Password=xxxx12345678" /> 

【讨论】:

    猜你喜欢
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多