Cannot fill my list if i am move it to new Thread
<p>i am use <code>SafeFileEnumerator</code> class to search for files inside folder root, this class return only files from location with permission so i am use it successfully.</p>

<p>when i try to fill my list in this way all works fine:</p>

<pre><code> List&lt;string&gt; list = new List&lt;string&gt;();
                    list = SafeFileEnumerator.EnumerateFiles(folderBrowserDialog1.SelectedPath,
                        "*.*", SearchOption.AllDirectories).ToList();
</code></pre>

<p>but in this case my GUI freeze so i move it to new thread and in this case nothing happen and i wondered why:</p>

<pre><code>private void btnAddDir_Click(object sender, EventArgs e)
{
    List&lt;string&gt; list = new List&lt;string&gt;();
    string fileToAdd = string.Empty;
    List&lt;string&gt; filesList = new List&lt;string&gt;();
    dialog = folderBrowserDialog1.ShowDialog();
    tbAddDir.Text = folderBrowserDialog1.SelectedPath;
    string pathToSearch = folderBrowserDialog1.SelectedPath;
    if (dialog == DialogResult.OK)
    {
        toolStripStatusLabel.Text = "Search for pcap files...";
        groupBoxRootDirectory.Enabled = false;
        btnStart.Enabled = false;                

        ThreadStart starter = delegate
        {
            list = SafeFileEnumerator.EnumerateFiles(pathToSearch, "*.pcap", SearchOption.AllDirectories).ToList();
        };

        Thread t = new Thread(starter);
        t.IsBackground = true;
        t.Start();

        if(list.Count != 0)
            AddFilesToListBox(list);
    }
}
</code></pre>

<p><strong>SafeFileEnumerator class code:</strong></p>

<pre><code>public static class SafeFileEnumerator
{
    public static IEnumerable&lt;string&gt; EnumerateDirectories(string parentDirectory, string searchPattern, SearchOption searchOpt)
    {
        try
        {
            var directories = Enumerable.Empty&lt;string&gt;();
            if (searchOpt == SearchOption.AllDirectories)
            {
                directories = Directory.EnumerateDirectories(parentDirectory).SelectMany(x =&gt; EnumerateDirectories(x, searchPattern, searchOpt));
            }
            return directories.Concat(Directory.EnumerateDirectories(parentDirectory, searchPattern));
        }
        catch (UnauthorizedAccessException ex)
        {
            return Enumerable.Empty&lt;string&gt;();
        }
    }

    public static IEnumerable&lt;string&gt; EnumerateFiles(string path, string searchPattern, SearchOption searchOpt)
    {
        try
        {
            var dirFiles = Enumerable.Empty&lt;string&gt;();
            if (searchOpt == SearchOption.AllDirectories)
            {
                dirFiles = Directory.EnumerateDirectories(path).SelectMany(x =&gt; EnumerateFiles(x, searchPattern, searchOpt));
            }

            return dirFiles.Concat(Directory.EnumerateFiles(path, searchPattern));
        }
        catch (UnauthorizedAccessException ex)
        {
            return Enumerable.Empty&lt;string&gt;();
        }
    }
}
</code></pre>

<p>after my list is full of files:</p>

<pre><code>private void AddFilesToListBox(List&lt;string&gt; filesList)
{
    string fileToAdd = string.Empty;
    Editcap editcap = new Editcap();
    Capinfos capinfos = new Capinfos();
    BackgroundWorker backgroundWorker = new BackgroundWorker();
    backgroundWorker.WorkerReportsProgress = true;
    backgroundWorker.DoWork +=
        (s1, e1) =&gt;
        {
            foreach (string fileName in filesList)
            {
                FileInfo fileInfo = new FileInfo(fileName);
                if (checkFileCreationDate(fileInfo))
                {
                    if (editcap.isWiresharkFormat(fileInfo.FullName))
                    {
                        if (editcap.isLibpcapFormat(fileInfo.FullName))
                        {
                            addFileToListBox(fileInfo.FullName, capinfos.getFileDuration(fileInfo.FullName));
                        }
                        else if (!editcap.isLibpcapFormat(fileInfo.FullName))
                        {
                            fileToAdd = editcap.getNewFileName(fileInfo.FullName);

                            if (new FileInfo(fileToAdd).Exists &amp;&amp; !fileInfo.Exists)
                            {
                                addFileToListBox(fileToAdd, capinfos.getFileDuration(fileInfo.FullName));
                            }
                        }
                    }
                }

                //this.Invoke((MethodInvoker)delegate { lvFiles.Items[lvFiles.Items.Count - 1].Selected = true; });
                toolStripStatusLabel.Text = string.Format("{0} files were added", lvFiles.Items.Count);
            }

            //this.Invoke((MethodInvoker)delegate { lvFiles.Items[lvFiles.Items.Count - 1].Selected = true; });
        };

    backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
    (s1, e1) =&gt;
    {
        groupBoxRootDirectory.Enabled = true;
        btnClear.Enabled = true;
        if (lvFiles.Items.Count != 0)
            btnStart.Enabled = true;
        toolStripStatusLabel.Text = string.Format("{0} files were added", lvFiles.Items.Count);

        if (tbAddDir.Text != "")
        {
            listener = new FileListener();
            listener.startListener(tbAddDir.Text);
            listener._newFileEventHandler += listener_newFileEventHandler;
        }
    });

    backgroundWorker.RunWorkerAsync();
}
</code></pre>
