unmanaged exception
?? 这个文件在哪里设置,还没找到,后面有需要了在处理
在托管程序的.config文件里,启用legacyCorruptedStateExceptionsPolicy这个属性,即简化的.config文件类似下面的文件:
<?xml version="1.0"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> <runtime> <legacyCorruptedStateExceptionsPolicy enabled="true" /> </runtime> </configuration>
|
在需要捕捉破坏性异常的函数外面加一个HandleProcessCorruptedStateExceptions属性,这个属性只控制一个函数,对托管程序的其他函数没有影响
[HandleProcessCorruptedStateExceptions] void function() { try { } catch (Exception e) { }finally { // 关闭数据库 if (cn.State == ConnectionState.Open) { cn.Close(); } cn.Dispose(); cmd.Dispose(); transaction.Dispose(); } }
|
比较返回值
try { mmf = MemoryMappedFile.CreateNew("fireworksShareMemory", mmf_size);
taskPythonPlugin = new Task(() => { Console.WriteLine("task python plugin start..."); task_pyton_plugin(); });
taskPythonPlugin.Start();
while (FLAG_PYTHON_LISTENING !=( flag & FLAG_PYTHON_LISTENING )) { Thread.Sleep(100); }
} catch (System.IO.IOException ex) { if ((uint)ex.HResult == 0x800700b7) { // 文件已存在,需要关闭之前未推出的进程。 Console.WriteLine("init mmf failed. " + ex.Message); } Console.WriteLine("init mmf failed. " + ex.Message); Log.Error("init mmf failed. " + ex.Message); }
|