Process.Kill() related crashes
<p>Or not!</p>

<p>I have a fairly simple application timer program. The program will launch a user selected (from file dialog) executable and then terminate the process after the user specified number of minutes.  During testing I found that a crash occurs when I call the Process.Kill() method and the application is minimized to the system tray.</p>

<p>The executable in question is Frap.exe which I use frequently and is the reason I wrote the app timer in the first place.  I always minimize fraps to the tray, and this is when the crash occurs.</p>

<p>My use of Kill() is straight forward enough...</p>

<pre><code>while (true)
        {
            //keep checking if timer expired or app closed externally (ie. by user)
            if (dtEndTime &lt;= DateTime.Now || p.HasExited)
            {
                if (!p.HasExited)
                    p.Kill();
                break;
            }
            System.Threading.Thread.Sleep(500);
        }
</code></pre>

<p>In searching for alternatives methods to close an external application programmatically, I found only Close() and Kill() (CloseMainWindow is not helpful to me at all).  I tried using Close(), which works providing the application is minimized the tray.  If the app is minimized, Close() doesn't cause a crash but the app remains open and active.
One thing I noticed in a few posts posts regarding closing external applications was the comment: "Personally I'd try to find a more graceful way of shutting it down though." made in <a href="http://stackoverflow.com/questions/673031/process-close-is-not-terminating-created-process-c">THIS</a> thread found here at stack flow (no offense to John).  Thing is, I ran across comments like that on a few sites, with no attempt at what a graceful or elegant (or crash-free!!) method might be.</p>

<p>Any suggestions?  </p>

<p>The crash experienced is not consistant and I've little to offer as to details.  I am unable to debug using VS2008 as I get message - cant debug crashing application (or something similar), and depending on what other programs I have running at the time, when the Kill() is called some of them also crash (also programs only running in the tray) so I'm thinking this is some sort of problem specifically related to the system tray. </p>
