求助一个C# WinForm下,关于System.OutOfMemoryException的一个问题

dgxlaen 2012-04-08 11:16:07
我用WCF寄宿在C# WinForm下,WCF使用的是netTCPBinding,并且使用了回调,WINFORM中加载了多个动态库,其中动态库在其它软件(如DELPHI中已经使用,非常稳定)。现在有这么一个问题,软件运行16~20个小时后自动崩溃退出了,我在主线程捕获的异常为:

CurrentDomain_UnhandledException-->2012-4-4 16:02:36 出现应用程序未处理的异常
异常类型:OutOfMemoryException
异常消息:Exception of type 'System.OutOfMemoryException' was thrown.
异常位置:
at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal(Delegate d)
at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(Delegate d)
at System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
at System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
at System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Timer.TimerNativeWindow.EnsureHandle()
at System.Windows.Forms.Timer.TimerNativeWindow.StartTimer(Int32 interval)
at System.Windows.Forms.Timer.set_Enabled(Boolean value)
...全文
1164 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2012-04-08
  • 打赏
  • 举报
回复
是不是用了Timer。在WCF中使用Windows窗体不太好。
  • 打赏
  • 举报
回复
OutOfMemoryException
应该是加载的一些资源没有及时释放,最后导致的内存溢出。
morecoding 2012-04-08
  • 打赏
  • 举报
回复
关注中
dgxlaen 2012-04-08
  • 打赏
  • 举报
回复
我觉得不是WCF的问题。有没有可能是调用动态库的问题呢。我调用动态库是先用DllImport引入LoadLibrary,然后用
private delegate int DriverInit(string DriverGUID, ref Int32 Did);
然后
private DriverInit FlpfDriverInit;
再用
_FDLLHandle = LoadLibrary(FileName);
if (_FDLLHandle == 0)
{
WriteLogFile("LoadLibrary初始化驱动失败");
re = false;
return re;
}

FlpfDriverInit = (DriverInit)GetFunctionAddress(_FDLLHandle, "DriverInit", typeof(DriverInit));
if (FlpfDriverInit == null)
{
FreeLibrary(_FDLLHandle);
WriteLogFile("获得接口函数DriverInit失败!");
re = false;
return re;
}
当然动态库接口函数还有很多,这儿只是举个例子,然后其中的一个动态库接口函数,我用线程去调用,当然是在得到事件通知的情况下。你觉得这样可能有问题吗?谢谢。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧