我用这个代码:非Invocable的错误时使用MethodInvoker
MethodInvoker TileLoadCompleteMethodInvoker = delegate()
{
CleanStatusLabelTimer.Enabled = true;
MemoryTextBox.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00} MB of {1:0.00} MB", MainMapControl.Manager.MemoryCache.Size, MainMapControl.Manager.MemoryCache.Capacity);
};
try
{
BeginInvoke(TileLoadCompleteMethodInvoker);
}
catch (TargetInvocationException ex)
{
BLL.FunctionsClass.LogExceptions(ex.InnerException);
}
LogExceptions方法是在这里:
public class LogExceptions
{
public static void WriteLogException(Exception exMsg)
{
string filePath = Application.StartupPath + "\\ExceptionLog.log";
using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
{
file.WriteLine("-------------------Exception Begin----------------------");
file.WriteLine(string.Format("Date: {0}, Time: {1}", DateTime.Now.ToShortTimeString()));
file.WriteLine(string.Format("Exception Message: {0}", exMsg.ToString()));
file.WriteLine(string.Format("Source: {0}", exMsg.Source));
file.WriteLine("-------------------Exception End----------------------");
file.WriteLine();
}
}
}
这种方法保存日志文件例外。但在调用LogExceptions方法时发生此错误; 非调用成员'IslamAtlas.BLL.FunctionsClass.LogExceptions'不能像方法一样使用。 我该如何解决这个问题?谢谢。
我使用的InnerException,但不正确的,错误happend。 :D我修正string.format。 –
@ 1mohammadi.ir:你看到我和leppie的答案了吗?您**必须**用函数名称* WriteLogException *更改您的代码。 – Marco
谢谢。这是一个愚蠢的问题,感谢很多人。 –