我该如何调试这StackOverflowException在我的WinForm应用程序? [英] How can I debug this StackOverflowException in my WinForm application?

查看:102
本文介绍了我该如何调试这StackOverflowException在我的WinForm应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm应用程序。每隔几秒钟,我查了一些日志文件,读取任何新的数据,并插入任何新的数据到数据库中。

I have a winform application. Every few seconds I check some log files, read in any new data and insert any new data into a DB.

当我运行应用程序的一个小时左右的1/2,我收到了 StackOverflowException 。有在这整个期间日志文件没有新的数据,所以没有什么新加入到​​该块中。

When I run the application for around an hour 1/2, I get a StackOverflowException. There was no new data in the log files for that entire period, so nothing new was added to the DB.

在code在这里出错......

The code errored here...

if (pictureBox == null)
{
    continue;
}

if (pictureBox.InvokeRequired)
{
    var toolTip = new ToolTip();
    GameServer tempGameFile = gameServer;
    pictureBox.Invoke(new MethodInvoker(
        () => toolTip.SetToolTip(pictureBox,
            string.Format(
                "{0} : Last Checked: {1}; Last Updated: {2}",
                tempGameFile.Name,
                tempGameFile.CheckedOn.ToLongTimeString(),
                tempGameFile.UpdatedOn.HasValue
                    ?
                        tempGameFile.UpdatedOn.Value.ToLongTimeString()
                        : "-No Date Set-"))));
}
pictureBox.Image = Resources.RedButton;

pictureBox.Invoke(..)是抛出的错误。

所以...我不知道我怎么能bebug这个要弄清楚到底是怎么回事?有什么建议?

So .. i'm not sure how I can bebug this to figure out what is going on? Any suggestions?

梅德的我已经开始了蚂蚁探查内存配置文件..并具有快速看一下东西..似乎有很多的工具提示控件实例。

Trying the suggestions of Dmitry I've started an ANTS profiler memory profile .. and having a quick look at things .. there seems to be a lot of instances of ToolTip controls.

这是20分钟后一类名单汇总。

This is a class list summary after 20 mins.

很多事件处理的(我不能放东西吗?)

Lots of EventHandlers (am I not releasing something?)

和里面的几个工具提示还...

And there's a few ToolTips also...

这里是所有实例的截图和的这里是一个单一的工具提示控制图/地图的截图 ..我不知道如何读的腮红

Here is a screenshot of all the instances and here is a screenshot of a single ToolTip control graph/map .. which I don't know how to read blush

推荐答案

您有两个潜在的问题与你的code:

You have 2 potential issues with your code:

VAR工具提示=新的工具提示();

pictureBox.Image = Resources.RedButton;

都呼吁非UI线程。我有<一个href="http://stackoverflow.com/questions/7153814/c-winform-backgroundworker-problem/7153841#7153841">marshal使用 Control.Invoke 。如果修复这没有帮助,看我如何在<调试StackOverflowException答案href="http://stackoverflow.com/questions/7222751/tracking-down-a-stackoverflow-error-in-an-windows-service/7222861#7222861">windows服务。

are both called on non-UI thread. I have to marshal this code to UI thread using Control.Invoke. If fixing this does not help, look at my answer on how to debug StackOverflowException in windows service.

更新:试试这个code。需要注意的是需要每一个引用任何UI控制语句使用Control.Invoke编组:

UPDATE: try this code. Note that every statement that references any UI control needs to be marshaled using Control.Invoke:

if (pictureBox == null || !pictureBox.IsHandleCreated) {
    continue;
}

Action setTooltipAndImage = () => {
    var toolTip = new ToolTip();
    GameServer tempGameFile = gameServer;
    toolTip.SetToolTip(pictureBox, string.Format(...));
    pictureBox.Image = Resources.RedButton;
};

if (pictureBox.InvokeRequired) {                        
    pictureBox.Invoke(setTooltipAndImage);
} else {
    setTooltipAndImage();
}

这可能值得一读从线程操作控件

这篇关于我该如何调试这StackOverflowException在我的WinForm应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆