发布于 2024-12-01 18:00:03 字数 2022 浏览 2 评论 0原文

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.

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.

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;

and the pictureBox.Invoke(..) is throwing that error.

So .. i'm not sure how I can bebug this to figure out what is going on?有什么建议吗?

UPDATE

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.

This is a class list summary after 20 mins.

enter image description here

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

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.

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.

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;

and the pictureBox.Invoke(..) is throwing that error.

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

UPDATE

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.

This is a class list summary after 20 mins.

enter image description here

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反话 2024-12-08 18:00:03

continue

You have 2 potential issues with your code:

var toolTip = new ToolTip();

and

pictureBox.Image = Resources.RedButton;

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.

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();
}

It might worth reading Manipulating Controls from Threads.

空宴 2024-12-08 18:00:03

如果您可以在调试模式下运行您的应用程序,当您遇到 StackOverflowException 并且应用程序中断到 Visual Studio 时,请打开调用堆栈窗口(调试 -> Windows -> 调用堆栈)并查看导致您的问题的原因。抛出异常的代码。

If you can run your application in debug mode, when you hit the StackOverflowException and the application breaks into visual studio, open up the call stack window (Debug -> Windows -> Call Stack) and take a look at what is causing your code to throw the exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文