Method to delete files in c#
<p>I have this simple method of deleting list of files. But for some cases it fails to delete the file unless i give it Sleep for some seconds. This is visible especially when i merge Word Documents using Interop and then right after executing merging i try to delete the files it fails to do so for some of them (as i guess Word is still in background). </p>

<p>What would be your approach on this one? Have it async and make it spawn a thread that would start deleting files after a while (kinda like garbage collector?)</p>

<pre><code>    public static void deleteDocuments(List&lt;string&gt; arrayList) {
        foreach (var item in arrayList) {
            try {
                File.Delete(item);
            } catch (Exception e) {
                MessageBox.Show("Błąd kasowania: " + e.ToString(), "Błąd Kasowania", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
    }
</code></pre>
