我正在尝试使用 Parallel.For() 将 n # 个平面文件加载到数据库中。每次迭代都需要在一个文件夹中创建 2 个配置文件,然后运行另一个使用配置文件的进程来了解如何将平面文件加载到 Oracle 中。在我决定使用并行选项之前,我通过迭代 1000 次来测试性能优势,每次都创建配置文件。我的速度提高了 2 倍以上。
然后,我添加了调用另一个进程的部分,并且我收到周期性错误,即我尝试在每次迭代中创建的一些配置文件不存在。
这是我的精简代码:
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;
}
错误示例: SQL Loader-500: Unable to open file (6f46ccfd-986e-427e-ab63-b7ce2396488e.ctl) SQL Loader-553: file not found SQL*Loader-509: System error: The system cannot find the file specified