winform程序问题求助!!!

suiyuan110 2010-12-03 06:38:39
写了一个C# winform的信息采集程序,也能实现采集功能,不过现在遇到的问题是,因为程序要整天运行,有的时候会出现自动退出问题,大概两三个小时左右就自动退出。为了定位错误信息,我在每个方法中都catch了并记录错误日志,但是一点痕迹也没有,貌似根本就不走catch 就直接给退了⊙﹏⊙b汗,快郁闷死了,不知道怎么回事。还有其它什么方法进行异常定位吗
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
whrspsoft3723 2010-12-03
  • 打赏
  • 举报
回复
二楼的方法应该可行。
另外,这类程序建议你尽可以多做日志,记录在文本中。到时退出了,知道执行的是什么条件 。有利于分析。

无原因退出是因为,错误发生在你没有加 try的地方。

另外,你用二楼的方法捕获到错误后,打印(抽象)下调用堆栈。
乌拉881 2010-12-03
  • 打赏
  • 举报
回复
自动退出可能是因为你的.NET版本不够,尝试安装.NET 3.5 SP1完整版试试,大概238M的包
机器人 2010-12-03
  • 打赏
  • 举报
回复
修改Main方法为如下,怀疑是有未捕获的Thread异常导致的?

// Starts the application. 
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
public static void Main(string[] args)
{
// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);

// Set the unhandled exception mode to force all Windows Forms errors to go through
// our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

// Runs the application.
Application.Run(new ErrorHandlerForm());
}


http://msdn.microsoft.com/zh-cn/library/system.windows.forms.application.threadexception.aspx
suiyuan110 2010-12-03
  • 打赏
  • 举报
回复
怎么没人回应呀,晕,到底应该怎么解决呢

110,571

社区成员

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

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

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