私はいくつかの画像をダウンロードし、それらをarrarListに入れて後で処理するプロジェクトに取り組んでいます。コードの次の部分に問題があります。それは最初のダウンロードで動作しますが、どういうわけか最初のダウンロード後に保存されていたファイル イメージがロックされます。ロックを解除する方法が見つからないようです。File.Delete("BufferImg"); 「BufferImg」がプログラムの他の場所で使用されていない場合、ファイルが別のプロセスによって使用されているというエラーが発生します。私は何を間違っていますか?
int attempcnt=0;
if (ok)
{
System.Net.WebClient myWebClient = new System.Net.WebClient();
try
{
myWebClient.DownloadFile(pth, "BufferImg");
lock (IMRequest) { IMRequest.RemoveAt(0); }
attempcnt = 0;
}
catch // will attempcnt 3 time before it remove the request from the queue
{
attempcnt++;
myWebClient.Dispose();
myWebClient = null;
if(attempcnt >2)
{
lock (IMRequest) { IMRequest.RemoveAt(0); }
attempcnt = 0;
}
goto endofWhile;
}
myWebClient.Dispose();
myWebClient = null;
using (Image img = Image.FromFile("BufferImg"))
{
lock (IMBuffer)
{
IMBuffer.Add(img.Clone());
MessageBox.Show("worker filled: " + IMBuffer.Count.ToString() + ": " + pth);
}
img.Dispose();
}
}
endofWhile:
File.Delete("BufferImg");
continue;
}