Im using backgroundworker to call a search for files function but its getting stuck for sometimes why?
<p>In the top of the Form1 i have:</p>

<pre><code>int searchTime;
        public TimeSpan ts_timeElapsed;
        DirectoryInfo dirinf = new DirectoryInfo(@"C:\");
        List&lt;FileSystemInfo&gt; fsi = new List&lt;FileSystemInfo&gt;();
        List&lt;string&gt; texts = new List&lt;string&gt;();

        public Form1()
        {
            InitializeComponent();

            label6.Visible = false;
            searchTime = 0;
            label4.Visible = false;
        }
</code></pre>

<p>Then i have a button click wich start the backgroundworker:</p>

<pre><code>private void button1_Click(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
            button1.Enabled = false;
            timer1.Enabled = true;
        }
</code></pre>

<p>Then the DoWork event:</p>

<pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Search(".xml", dirinf, fsi);
            backgroundWorker1.ReportProgress(100);

        }
</code></pre>

<p>Then the Search function code:</p>

<pre><code>public void Search(string strExtension,
                            DirectoryInfo di,
                            List&lt;FileSystemInfo&gt; pResult)
        {
            try
            {

                foreach (FileInfo fi in di.GetFiles())
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke(new Action(() =&gt; label2.Text = fi.Name));
                    }
                    if (fi.Name == "MessageLog.xsl")
                    {
                        foreach (FileInfo fii in di.GetFiles())
                        {
                        if (fii.Extension == strExtension)
                            pResult.Add(fii);
                        }
                        if (InvokeRequired)
                        {
                            BeginInvoke(new Action(() =&gt; label4.Text = pResult.Count.ToString() + Environment.NewLine));
                        }

                    }
                }

                    foreach (DirectoryInfo diChild in di.GetDirectories())
                        Search(strExtension, diChild, pResult);

            }
            catch (Exception e)
            {
            }
        }
</code></pre>

<p>The search start at c:\ but soon as the search process start on the first or after 5 files its getting stuck on a file i cant event click anything even if its working with a backgorundworker its like everything the program got stuck for some seconds then its continue for some seconds searching more files then stuck again. And when its stuck i mean its freezing i cant click anything about the application.</p>

<p>Then after few times its searching fast and smooth but i dont get it why in the begining it  stuck few times ?</p>
