我不久前写的一个应用程序遇到了一个非常奇怪的问题。它可以正常工作,但是在放置一段时间后,它就停止了工作。我将在此处附上代码:
try
{
using (Process proc = Process.Start(starter))
{
windowHider();
proc.WaitForExit();
DateTime endStamp = DateTime.Now;
endStamp = truncate(endStamp);
TimeSpan diff = endStamp.Subtract(startStamp);
string programSource = "applicationName";
string logLocation = "Application";
string occurance = "Var='" + varName + "' Var2='"+ var2Name + "' Var3='" + var3Name + "' Var4='" + var4Name + "' Var5='" + var5Name + "' Var6='" + var6Name + "'";
try
{
if (!EventLog.SourceExists(programSource))
{
EventLog.CreateEventSource(programSource, logLocation);
}
else
{
EventLog.WriteEntry(programSource, occurance);
}
}
catch (Exception err)
{
string message = "There was an error with usage logging. Please contact IT.";
MessageBox.Show(message);
errorLogger(message, err.ToString(), ((Control)sender).Name);
this.Close();
}
this.Close();
}
}
当启动的进程退出时,程序将写入应用程序日志。但是,由于某种原因,我收到以下错误:
异常:System.ComponentModel.Win32Exception (0x80004005):指定路径无效
它引用这条线作为原因:
EventLog.WriteEntry(programSource, occurance);
关于这个突然的问题可能是什么的任何想法?