线程和递归的运用
最近写了一段小代码 ,想了解线程的应用,但是发现递归和线程用到一起就会出现堆栈溢出的问题 。不知道怎么解决,请教高手帮忙
下面是我的实例代码
DataTable dt = new DataTable();
System.Threading.Thread th;
private void button1_Click(object sender, EventArgs e)
{
th = new System.Threading.Thread(new System.Threading.ThreadStart(star));
th.Start();
}
private void star()
{
try
{
int i = 0;
i++;
CheckForIllegalCrossThreadCalls = false;
dt.Rows.Clear();
System.Threading.Thread.Sleep(10);
star();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
---------------------------------------------------------------------
上面会报错
未处理的“System.StackOverflowException”类型的异常出现在 System.Data.dll 中。