I\'ve to call a function recursively. But after a moment it throws StackOverFlowException. When I used Invoke(new Action(Start)) method, it throws same exception but not in
When the last statement in a function is the call to the function itself, you have tail-recursion. While there are languages that optimize tail-recursion to avoid a stack overflow exception, C# is not one of them.
Recursion is not a good pattern for data that can be of an arbitrary length. Simply replace recursion by a while loop:
private void Start()
{
while(true) {
// run select query
mysql(selectQueryString.ToString());
msdr = mysql();
// is finished
if (!msdr.HasRows)
{
this.Finish();
break;
}
// rest of your code..
}
}