Tag: 堆栈溢出

如何在WinForm应用程序中调试此StackOverflowException?

我有一个winform应用程序。 每隔几秒我检查一些日志文件,读入任何新数据并将任何新数据插入数据库。 当我运行应用程序大约一个小时1/2时,我得到一个StackOverflowException 。 整个期间的日志文件中没有新数据,因此没有新的数据添加到数据库中。 代码在这里出错… 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(..)抛出该错误。 那么..我不知道我怎么能想到这一点来弄清楚发生了什么? 有什么建议? […]

StackOverflowException未处理

我的代码中出现此错误 MedCareProviderLibrary.dll中发生未处理的“System.StackOverflowException”类型exception 这是我的代码片段以及错误的来源。 它会在出现错误的部分给出一个黄色箭头。 显示错误的部分以粗体显示。 任何帮助将不胜感激谢谢 private string _TestNo; private string _TestType; private DateTime _TestDate; private string _PatientNo; private string _DoctorNo; public Test() { _TestNo = “”; _TestType = “”; _TestDate = new DateTime(); _PatientNo = “”; _DoctorNo = “”; } public Test(string aTestNo, string aTestType, DateTime aTestDate, string aPatientNo, string aDoctorNo) { _TestNo = […]

C# – 查找图像的边界(不是大小)

我正在开发一个应用程序来均匀地分割图像网格并使图像居中(基于它们的相似性)。 到目前为止,我可以设法修复一个小尺寸的图像网格,但每当我尝试更大的“精灵”大小(例如100×100)时,我就会出现Stack Overflow错误。 是的我正在使用递归,但每当检查一个像素时,我设置一个布尔值来停用它,将它复制到一个列表并继续检查其他(在所有方向),直到列表填满了来自网格。 我不确定这是否是最佳方式,因为对于每次调用,我调用相同的方法7次(假设有7个相邻的像素尚未检查)…直到没有剩余的像素来检查,并且我可以转到网格中的下一个图像。 我尝试跟踪错误开始发生的地方,检查了大约1600像素并将它们添加到列表中。 MyPixel是一个包含4个变量的类:x(int),y(int),color(Color)和checked(bool) public void processSprite(int i, int j) { //OOO //OXO //OOO pixeltemp.Add(new MyPixel(imap.pixels[i, j].x, imap.pixels[i, j].y, imap.pixels[i, j].color)); imap.pixels[i, j].read = true; //OOO //OOX //OOO try { if (!imap.pixels[i + 1, j].read) { if (imap.pixels[i + 1, j].color.A == 0) //Found a Border { imap.pixels[i + 1, j].read = […]

执行FloodFill的不同方法

好的,我有几种不同的方法来执行FloodFill。 所有这些都会导致问题。 我将列出3种方法并解释每种方法会发生什么。 如果有人能给我一些很棒的指示。 我见过一些类似的post,但没有一个是C#,java或VB.net(我知道的唯一语言)。 对此的给予是我有一个名为PixelData的类,它将一个Color存储在CellColor成员变量中。 我有一个50×50 PixelData对象的数组,称为“像素”。 我也有一个名为CANVAS_SIZE的常量,在这种情况下为50。 以下是我尝试过的三种方法。 这个是递归的。 它非常容易出现堆栈溢出。 我已经尝试设置一个计时器,在此方法完成后启用CanFill成员。 这仍然不能防止溢出: private void FloodFill(Point node, Color targetColor, Color replaceColor) { //perform bounds checking X if ((node.X >= CANVAS_SIZE) || (node.X = CANVAS_SIZE) || (node.Y < 0)) return; //ouside of bounds //check to see if the node is the target color if (pixels[node.X, […]

洪水填充递归算法

我正在尝试制作一个可以在c#中填充int数组的算法。 基本上,作为MS Paint中的填充工具,我有一个颜色,如果我在数组中选择(x,y)坐标,它会用新颜色替换所有具有相同初始颜色的邻居。 例如: [0,0,0] [0,1,0] [1,1,0] 如果我将3放入(0,0),则数组变为: [3,3,3] [3,1,3] [1,1,3] 所以我在递归中尝试了它并且确实有效,但并非总是如此。 实际上,我有时会出现“Stack Overflow”错误(似乎合适)。 这是我的代码,如果你能告诉我什么是错的话会很棒:) public int[,] fill(int[,] array, int x, int y, int initialInt, int newInt) { if (array[x, y] == initialInt) { array[x, y] = newInt; if (x 0) array = fill(array, (x – 1), y, initialInt, newInt); if (y 0) array = […]

程序化按钮单击会抛出’System.StackOverflowException’exception

我在C#.Net中编写了一个WinForms程序,在密码表单中以编程方式单击按钮。 Form1加载并将Form2显示为对话框。 如果DialogResult是DialogResult.OK的其他任何东西,应用程序将关闭。 到目前为止,我有一个按钮单击事件,编码如下: if (txtpass.Text == “”) { MessageBox.Show(“You need to enter a password”, “Password”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); txtpass.Focus(); } else { if (txtpass.Text == “1234”) { radButton1.DialogResult = DialogResult.OK; radButton1.PerformClick(); } else { MessageBox.Show(“Password Incorrect”, “Password”, MessageBoxButtons.OK, MessageBoxIcon.Error); txtpass.Text = “”; txtpass.Focus(); } } 我用radButton1.PerformClick(); ,但运行该程序给我以下消息: An unhandled exception of type ‘System.StackOverflowException’ occurred in […]

在递归函数中防止StackOverFlow

我在BaseClass有一个递归函数,它依赖于protected virtual函数来获取它的返回条件。 子类可能会错误地覆盖此函数并导致StackOverFlowexception。 最糟糕的是网络呼叫速度很慢,而且不会很快发生exception(许多资源浪费了很长时间)。 我正在寻找一种方法来在早期阶段以某种方式在基类中检查StackOverFlow (可能使用Reflection和当前的递归级别)。 任何的想法 ?

在C#中使用递归

在使用递归来避免堆栈溢出时是否有任何一般规则?

如何防止我的Ackerman函数溢出堆栈?

有没有办法让我的Ackerman函数不会创建一个堆栈而不是流量是相对较小的数字,即(4,2)。 这是错误 {无法计算表达式,因为当前线程处于堆栈溢出状态。} private void Button1Click(object sender, EventArgs e) { var t = Ackermann(4,2); label1.Text += string.Format(“: {0}”, t); label1.Visible = true; } int Ackermann(uint m, uint n) { if (m == 0) return (int) (n+1); if (m > 0 && n == 0) return Ackermann(m – 1, 1); if (m > 0 && n […]