How do I test in C# if an exe is running correctly?
<p>I have a <code>viewer.exe</code> that loads at startup some models (<code>*.mdl</code>) from a "models" folder. Some of the models crash <code>viewer.exe</code>: "viewer.exe has stopped working. Windows can check online for a solution to the problem".<br>
What I could do is move all the <code>.mdl</code> files in a "source" folder and then manually test for each <code>.mdl</code> file moved to "models" if <code>viewer.exe</code> is running but, there are a lot of files to check.  How do I move each <code>*.mdl</code> file from "source" to "models" and test programmatically if <code>viewer.exe</code> is running correctly?</p>

<p>Here is the code I use for my first problem: to move the <code>.mdl files</code> from "source" folder sub-directories in "models". Some of the files had identical names but different size:</p>

<pre><code>String mask = "*.mdl";
String source = @"c:\Source\";
String destination = @"c:\Models\";

String[] files = Directory.GetFiles(source, mask, SearchOption.AllDirectories);
foreach (String file in files)
{
    if (File.Exists(file) &amp;&amp; !File.Exists(destination + new FileInfo(file).Name))
    {
        File.Move(file, destination + new FileInfo(file).Name);
    }
    else
    {
        FileInfo f = new FileInfo(file);
        long s = f.Length;
        FileInfo f2 = new FileInfo(destination + new FileInfo(file).Name);
        long s2 = f2.Length;
        if (s &gt;= s2)
        {
            File.Delete(destination + new FileInfo(file).Name);
            File.Move(file, destination + new FileInfo(file).Name);
        }
    }
}
</code></pre>
