C# 当我将应用程序作为服务运行时,如何处理System.AccessViolationException

C# 当我将应用程序作为服务运行时,如何处理System.AccessViolationException,c#,.net,opencv,windows-services,.net-4.5,C#,.net,Opencv,Windows Services,.net 4.5,事实上我在做OpenCV。我创建了两个应用程序,一个是windows窗体应用程序,另一个是窗口服务。这两个应用程序包含相同的代码。 当我以windows应用程序运行它时,一切正常。当我试图将其作为Windows服务运行时,它会引发异常 Application: DSG Service.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception.

事实上我在做OpenCV。我创建了两个应用程序,一个是windows窗体应用程序,另一个是窗口服务。这两个应用程序包含相同的代码。 当我以windows应用程序运行它时,一切正常。当我试图将其作为Windows服务运行时,它会引发异常

 Application: DSG Service.exe
 Framework Version: v4.0.30319
 Description: The process was terminated due to an unhandled exception.
 Exception Info: System.AccessViolationException
 at Emgu.CV.CvInvoke.CvCascadeClassifierDetectMultiScale(IntPtr, IntPtr,IntPtr, Double, Int32, Int32, System.Drawing.Size, System.Drawing.Size)
 at       Emgu.CV.CascadeClassifier.DetectMultiScale(Emgu.CV.Image`2<Emgu.CV.Structure.Gra  y,Byte>, Double, Int32, System.Drawing.Size, System.Drawing.Size)
 at DSG.Service.ReadMyFace.Timer_Frame_Grabber_Tick(System.Object,System.Timers.ElapsedEventArgs)
 at System.Timers.Timer.MyTimerCallback(System.Object)
 at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)
 at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 at System.Threading.TimerQueueTimer.CallCallback()
 at System.Threading.TimerQueueTimer.Fire()
 at System.Threading.TimerQueue.FireNextTimers()
 at System.Threading.TimerQueue.AppDomainTimerCallback()

Faulting application name: DSG Service.exe, version: 1.0.0.0, time stamp: 0x56fca95e
Faulting module name: opencv_objdetect2410.dll, version: 0.0.0.0, time stamp: 0x547df585
Exception code: 0xc0000005
Fault offset: 0x00028768
Faulting process id: 0xd40
Faulting application start time: 0x01d18b06f8432dbd
Faulting application path:      E:\Amit\Projects\DSG\DotNetClient\DSG.Application\DSG Service.exe
Faulting module path:   E:\Amit\Projects\DSG\DotNetClient\DSG.Application\x86\opencv_objdetect2410.dll
Report Id: 388a222d-f6fa-11e5-96cb-fcaa14a29764
我在谷歌上搜索过这个异常,他们说它会发生bcz内存管理不足。我如何克服这个异常

 Application: DSG Service.exe
 Framework Version: v4.0.30319
 Description: The process was terminated due to an unhandled exception.
 Exception Info: System.AccessViolationException
 at Emgu.CV.CvInvoke.CvCascadeClassifierDetectMultiScale(IntPtr, IntPtr,IntPtr, Double, Int32, Int32, System.Drawing.Size, System.Drawing.Size)
 at       Emgu.CV.CascadeClassifier.DetectMultiScale(Emgu.CV.Image`2<Emgu.CV.Structure.Gra  y,Byte>, Double, Int32, System.Drawing.Size, System.Drawing.Size)
 at DSG.Service.ReadMyFace.Timer_Frame_Grabber_Tick(System.Object,System.Timers.ElapsedEventArgs)
 at System.Timers.Timer.MyTimerCallback(System.Object)
 at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)
 at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 at System.Threading.TimerQueueTimer.CallCallback()
 at System.Threading.TimerQueueTimer.Fire()
 at System.Threading.TimerQueue.FireNextTimers()
 at System.Threading.TimerQueue.AppDomainTimerCallback()

Faulting application name: DSG Service.exe, version: 1.0.0.0, time stamp: 0x56fca95e
Faulting module name: opencv_objdetect2410.dll, version: 0.0.0.0, time stamp: 0x547df585
Exception code: 0xc0000005
Fault offset: 0x00028768
Faulting process id: 0xd40
Faulting application start time: 0x01d18b06f8432dbd
Faulting application path:      E:\Amit\Projects\DSG\DotNetClient\DSG.Application\DSG Service.exe
Faulting module path:   E:\Amit\Projects\DSG\DotNetClient\DSG.Application\x86\opencv_objdetect2410.dll
Report Id: 388a222d-f6fa-11e5-96cb-fcaa14a29764
应用程序:DSG Service.exe
框架版本:v4.0.30319
描述:由于未处理的异常,进程已终止。
异常信息:System.AccessViolationException
在Emgu.CV.CvInvoke.CvCascadeClassifierDetectMultiScale(IntPtr、IntPtr、IntPtr、Double、Int32、Int32、System.Drawing.Size、System.Drawing.Size)
在Emgu.CV.CascadeClassifier.DetectMultiScale(Emgu.CV.Image`2,Double,Int32,System.Drawing.Size,System.Drawing.Size)
在DSG.Service.ReadMyFace.Timer\u Frame\u Grabber\u Tick(System.Object,System.Timers.ElapsedEventArgs)
at System.Timers.Timer.MyTimerCallback(System.Object)
位于System.Threading.TimerQueueTimer.CallbackInContext(System.Object)
位于System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值)
在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值)
在System.Threading.TimerQueueTimer.CallCallback()中
在System.Threading.TimerQueueTimer.Fire()中
在System.Threading.TimerQueue.FireNextTimers()上
在System.Threading.TimerQueue.AppDomainTimerCallback()中
故障应用程序名称:DSG Service.exe,版本:1.0.0.0,时间戳:0x56fca95e
故障模块名称:opencv_objdetect2410.dll,版本:0.0.0.0,时间戳:0x547df585
异常代码:0xc0000005
故障偏移量:0x00028768
出错进程id:0xd40
故障应用程序启动时间:0x01d18b06f8432dbd
出错的应用程序路径:E:\Amit\Projects\DSG\DotNetClient\DSG.application\DSG Service.exe
故障模块路径:E:\Amit\Projects\DSG\DotNetClient\DSG.Application\x86\opencv\u objdetect2410.dll
报告Id:388a222d-f6fa-11e5-96cb-fcaa14a29764

它是否尝试在GUI方面做任何事情?不,这是一项windows服务,我们在GUI方面什么都不做…:(这可能是Windows服务的祸根-在服务之外一切正常,但在作为服务时却会起作用。我看到了
Emgu.CV.Image
,OpenCV支持Windows服务吗?是的,它作为Windows服务也可以正常工作,但有时它会给我System.AccessViolationException。