我必须递归调用一个函数。但片刻之后它会抛出 StackOverFlowException。当我使用 Invoke(new Action(Start)) 方法时,它会抛出相同的异常,但不会很长时间,这比前一个要短。
我该如何克服这个问题?
示例代码:
private void Start()
{
// run select query
mysql(selectQueryString.ToString());
msdr = mysql();
// is finished
if (!msdr.HasRows)
{
this.Finish();
return;
}
// get mysql fields
string[] mysqlFields = Common.GetFields(ref msdr);
while (msdr.Read())
{
// set lastSelectID
lastSelectID = Convert.ToInt32(msdr[idFieldName].ToString());
// fill mssql stored procedure parameters
for (int i = 0; i < matchTable.Count; i++)
{
string valueToAdd = Common.ConvertToEqualivantString(matchTable[i].Type, matchTable[i].Value, ref msdr, ref id, matchTable[i].Parameters);
sql.Ekle(matchTable[i].Key, valueToAdd);
}
// execute adding operation
lastInsertID = (int)sql(false);
// update status bar
this.UpdateStatusBar();
// update menues
this.UpdateMenues();
// increment id for "{id}" statement
id++;
}
// close data reader
msdr.Close();
msdr.Dispose();
mysql.DisposeCommand();
// increment select limit
selectQueryString.LimitFirst += selectQueryString.LimitLast;
// call itself until finish
this.Start();
}