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.
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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:
It might worth reading Manipulating Controls from Threads.
如果您可以在调试模式下运行您的应用程序,当您遇到 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.