Besides checking the Windows Event Viewer (from Computer Management) you could also try to build some error logging around your program. If you extend your Main()
method to contain the following lines you will be able to get some further information about the cause of the program failure:
[STAThread]
static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.Run(new Form1());
}
private static void Application_ThreadException(
object sender, ThreadExceptionEventArgs e)
{
//Log error here using e.Exception
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//Log error here using (Exception)e.ExceptionObjecte.Exception
}
You could for example log the error to a simple text file using a StreamWriter:
string dateStr = DateTime.Now.ToString("yyyy-MM-dd");
StreamWriter sw = File.AppendText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorLog_" + dateStr + ".log"));
sw.WriteLine(exception);