Parallel processing 找不到Parallel.For()文件的意外行为

Parallel processing 找不到Parallel.For()文件的意外行为,parallel-processing,task-parallel-library,console-application,parallel.for,Parallel Processing,Task Parallel Library,Console Application,Parallel.for,我正在尝试使用Parallel.For()将n个平面文件加载到数据库中。每次迭代都需要在一个文件夹中创建2个配置文件,然后运行另一个使用配置文件的进程,以了解如何将平面文件加载到Oracle中。在决定使用并行选项之前,我通过迭代1000次来测试性能优势,每次创建配置文件。我最好不要把速度提高两倍 然后,我添加了调用另一个进程的部分,我得到了一些周期性错误,这些错误是我在每次迭代中尝试创建的一些配置文件不存在的 这是我的精简代码: public static void FindFilesToLoa

我正在尝试使用Parallel.For()将n个平面文件加载到数据库中。每次迭代都需要在一个文件夹中创建2个配置文件,然后运行另一个使用配置文件的进程,以了解如何将平面文件加载到Oracle中。在决定使用并行选项之前,我通过迭代1000次来测试性能优势,每次创建配置文件。我最好不要把速度提高两倍

然后,我添加了调用另一个进程的部分,我得到了一些周期性错误,这些错误是我在每次迭代中尝试创建的一些配置文件不存在的

这是我的精简代码:

public static void FindFilesToLoad(int monitorId)
{
    //left out code here that calls a stored procedure to get a list of ids
    fileCount = idList.Count;
    if (fileCount  != 0)
        {
           Parallel.For(0, fileCount, 

                        i =>
                        {
                            fileId = Convert.ToInt32(idList[i]);
                            //do the work here...
                            LoadFileIntoDatabase(monitorId, fileId);
                        });
        }
}

public static void LoadFileIntoDatabase(int monitorId, int fileId)
{
     stamp = Guid.NewGuid().ToString();
     controlFile = CreateSqlLoaderControlFile(monitorId,stamp);
     controlFileName = Path.GetFileName(controlFile);
     parFile = CreateParFile(monitorId, controlFileName, stamp);

     myCommand = @"CMD.EXE";
     ProcessStartInfo startInfo = new ProcessStartInfo(myCommand)
         {
            WorkingDirectory = @"c:\temp\",
            Arguments = @"/c SQLLDR CONTROL=" + controlFile + " PARFILE=" + parFile ,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false
         };

     Process process = new Process();
     process.StartInfo = startInfo;
     process.Start();
     process.WaitForExit();
     exitCode = process.ExitCode;
}
错误示例: SQLLoader-500:无法打开文件(6f46ccfd-986e-427e-ab63-b7ce2396488e.ctl) SQLLoader-553:未找到文件
SQL*Loader-509:系统错误:系统找不到指定的文件

哪一行正确抛出
CreateSqlLoaderControl文件(monitorId,stamp)
?感谢您的回复。这与parallel.For()无关。这只是我在漫长的一天之后犯的一个愚蠢的错误。一切似乎都很顺利。我的开发机器(4个内核)的速度提高了3倍以上。对你有好处:)虽然SQL Loader没有一些.NET sdk,但你必须使用cmd.exe,这很奇怪。。。