How can i tell state of a thread?
<p>I need to know when is this thread finished with whatever is it doing. also have an active timer on background. </p>

<p>note: "scanner" is an recursive function </p>

<pre><code>// 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 &gt; 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);
    }

}
</code></pre>
