現在、大量のxmlファイルを処理し、xmlファイルからデータベースに情報を保存するWindowsサービスを作成しています。同じ共有場所を指す同じサービスを実行している 3 台のマシンがあります。プロセス中にファイルが見つからないという例外が常に発生し、この問題を解決する方法がわかりません。ディレクトリからすべてのファイルを取得し、マシン名に基づいてそれらのファイルの名前を変更し、各マシンが独自のファイルセットを処理できるようにしましたが、依然として File Not Found 例外が発生します。誰かがこれに対処する適切な方法を教えてくれませんか。
ありがとうございました。
コード
if (Directory.Exists(folder))
{
string pattern = ".xml";
string machineName = System.Environment.MachineName;
string[] files = Directory.GetFiles(folder, pattern, SearchOption.AllDirectories);
newExt = string.Format("{0}.{1}", machineName, newExt);
for (int i = 0; i < files.Length; i++)
{
if (files[i].Contains(machineName))
{
//replace this new extension
files[i].Replace(machineName + ".", "");
}
else
{
files[i] = ChangeExtension(files[i], newExt, true);
}
}
IEnumerable<string> sortedFiles = files.Where(f => !string.IsNullOrEmpty(f) && f.Contains(machineName))
.OrderBy(f => f, Sorter);
}