This program is purely experimental to try to understand these concepts. The full code from Form1.cs follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Multithreading__Test_2_
{
public partial class Form1 : Form
{
private int x = 0;
private int y = 12500;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Prevent the framework from checking what thread the GUI is updated from.
Form1.CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
button1.Visible = false;
progressBar1.Visible = true;
progressBar1.Maximum = y;
Thread workThread = new Thread(new ThreadStart(WorkThread));
workThread.Start();
}
void WorkThread()
{
if (x != y)
{
x++;
progressBar1.Value++;
WorkThread();
}
else
MessageBox.Show("Done");
}
}
}
This code, as-is, works perfectly fine. But for some reason, if I make y any bigger, say 13000 or larger, then I get a System.StackOverflowException suggesting that I've got an infinite recursion. Obviously, it would not be infinite recursion, it would end after just a few more iterations, but for some reason C# does not like it.
Why does this create a System.StackOverflowException situation and how can I prevent it? When I do this for my actual program, the work being done is a recursive operation that has the potential to recur more than 13,000 times so I am worried that I will get the same error there, and would like to try to correct it in this experimental situation before modifying the code of my other program.
Thanks in advance!

New Topic/Question
Reply





MultiQuote







|