我需要知道这个线程什么时候完成它正在做的事情。在后台也有一个活跃的计时器。
注意:“扫描仪”是一个递归函数
// button click
//timer
timer.Enabled = true;
//thread
System.Threading.ThreadStart start = delegate { scanner(@"c:\", "*.txt;*.html;"); };
System.Threading.Thread thread = new System.Threading.Thread(start);
thread.Start();
-------------
private static long Counter = 0;
private static string scanstatus = string.Empty;
private static void scanner(string folder, string patterns)
{
// Get the patterns.
string[] pattern_array = patterns.Split(';');
foreach (string pattern in pattern_array)
{
try
{
foreach (string fileName in System.IO.Directory.GetFiles(folder, pattern))
{
//trim path
scanstatus = (fileName.Length > 50) ? "../" + fileName.Substring(fileName.Length - 49, 49) : fileName;
// delay
//System.Threading.Thread.Sleep(5);
Counter++;
}
}
catch (System.Exception E)
{
Console.WriteLine(E.Message);
}
}
try
{
foreach (string directory in System.IO.Directory.GetDirectories(folder))
scanner(directory, patterns);
}
catch (System.Exception E)
{
Console.WriteLine(E.Message);
}
}