시스템 스레드를 사용하여 폴더를 반복하면서 파일 액세스가 거부되면 무시하고 계속하는 방법.파일에 대한 액세스가 거부되면 스레드 캐치 계속
// Start thread.
System.Threading.ThreadStart start = delegate { scanner(@"C:\", "*.html;*.txt"); };
System.Threading.Thread thread = new System.Threading.Thread(start);
thread.Start();
private static string scanstatus = string.Empty;
private static void scanner(string folder, string patterns)
{
try
{
// Get the patterns.
string[] pattern_array = patterns.Split(';');
// Search.
foreach (string pattern in pattern_array)
{
foreach (string path in System.IO.Directory.GetFiles(folder, pattern, System.IO.SearchOption.AllDirectories))
{
// trim path
scanstatus = (path.Length > 60) ? "../" + path.Substring(path.Length - 59, 59) : path;
System.Threading.Thread.Sleep(5000);
}
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
finally
{
Console.WriteLine("*************DONE*************");
}
}
'try-catch'를 루프 안에 넣는 것이 무슨 문제입니까? –
계속되지 않습니다. 내가 뭘 잘못했는지 모르겠다. –
루프 내부에'try-catch' **를 넣어야한다. 당신은 ** 외부 루프 **를 가지고 있습니다 ... –