私が受け取っている完全なエラーは次のとおりです。
「このプロセスは、ファイル 'e:\Batch\NW\data_Test\IM_0232\input\RN318301.WM' にアクセスできません。別のプロセスで使用されているためです。>>> at IM_0232.BatchModules.BundleSort(String bundleFileName) at IM_0232. BatchModules.ExecuteBatchProcess()"
関連するコードを以下に示します。処理中のRN318301.WM
ファイルは、最終的に PDF ドキュメントに配置される情報を含むテキスト ファイルです。テキスト ファイルには多数のドキュメントが参照されておりRN318301.WM
、それぞれが行のコレクションで表されています。コードからわかるように、RN318301.WM
テキスト ファイルは最初に解析され、そのファイルに含まれるドキュメントの数と、ドキュメントの最大行数が決定されます。次に、この情報を使用して、すべてのドキュメント情報を含む 2 次元配列を作成します。テキスト ファイルはRN318301.WM
再度解析されて 2 次元配列に入力され、同時に情報が辞書に収集され、後でルーチンで並べ替えられます。
障害は、次の最後の行で発生します。
File.Delete(_bundlePath + Path.GetFileName(bundleFileName));
これは、まれにしか発生しない散発的な問題です。以前は発生していなかった特定のテキスト ファイルで発生することさえ確認されています。つまり、特定のテキスト ファイルは正常に処理されますが、再処理するとエラーが発生します。
このエラーの原因を診断するのを手伝ってくれる人はいますか? どうもありがとうございました...
public void BundleSort(string bundleFileName)
{
Dictionary<int, string> memberDict = new Dictionary<int, string>();
Dictionary<int, string> sortedMemberDict = new Dictionary<int, string>();
//int EOBPosition = 0;
int EOBPosition = -1;
int lineInEOB = 0;
int eobCount = 0;
int lineCount = 0;
int maxLineCount = 0;
string compareString;
string EOBLine;
//@string[][] EOBLineArray;
string[,] EOBLineArray;
try
{
_batch.TranLog_Write("\tBeginning sort of bundle " + _bundleInfo.BundleName + " to facilitate householding");
//Read the bundle and create a dictionary of comparison strings with EOB position in the bundle being the key
StreamReader file = new StreamReader(@_bundlePath + _bundleInfo.BundleName);
//The next section of code counts CH records as well as the maximum number of CD records in an EOB. This information is needed for initialization of the 2-dimensional EOBLineArray array.
while ((EOBLine = file.ReadLine()) != null)
{
if (EOBLine.Substring(0, 2) == "CH" || EOBLine.Substring(0, 2) == "CT")
{
if (lineCount == 0)
lineCount++;
if (lineCount > maxLineCount)
{
maxLineCount = lineCount;
}
eobCount++;
if (lineCount != 1)
lineCount = 0;
}
if (EOBLine.Substring(0, 2) == "CD")
{
lineCount++;
}
}
EOBLineArray = new string[eobCount, maxLineCount + 2];
file = new StreamReader(@_bundlePath + _bundleInfo.BundleName);
try
{
while ((EOBLine = file.ReadLine()) != null)
{
if (EOBLine.Substring(0, 2) == "CH")
{
EOBPosition++;
lineInEOB = 0;
compareString = EOBLine.Substring(8, 40).Trim() + EOBLine.Substring(49, 49).TrimEnd().TrimStart() + EOBLine.Substring(120, 5).TrimEnd().TrimStart();
memberDict.Add(EOBPosition, compareString);
EOBLineArray[EOBPosition, lineInEOB] = EOBLine;
}
else
{
if (EOBLine.Substring(0, 2) == "CT")
{
EOBPosition++;
EOBLineArray[EOBPosition, lineInEOB] = EOBLine;
}
else
{
lineInEOB++;
EOBLineArray[EOBPosition, lineInEOB] = EOBLine;
}
}
}
}
catch (Exception ex)
{
throw ex;
}
_batch.TranLog_Write("\tSending original unsorted bundle to archive");
if(!(File.Exists(_archiveDir + "\\" +DateTime.Now.ToString("yyyyMMdd")+ Path.GetFileName(bundleFileName) + "_original")))
{
File.Copy(_bundlePath + Path.GetFileName(bundleFileName), _archiveDir + "\\" +DateTime.Now.ToString("yyyyMMdd")+ Path.GetFileName(bundleFileName) + "_original");
}
file.Close();
file.Dispose();
GC.Collect();
File.Delete(_bundlePath + Path.GetFileName(bundleFileName));