Forgive my terminology, I'm not all that familiar with System.Threading
, but if I have something like the below:
private static int _index;
private static List<int> _movieIds = new List<int>();
static void Main(string[] args)
{
// the below call populates the _movieIds list variable with around 130,000 ints
GetListOfMovieIdsFromDatabase();
_index = 0;
Thread myThread = new Thread(DoWork);
myThread.Start();
}
public static void DoWork()
{
// do something with the value of _index (iterate through the _movieIds list) then recursively call DoWork() again
Thread.Sleep(400);
_index++;
DoWork();
}
Is this bad practice? I am iterating through a private static list of int's
defined at the class level as a member, so the first iteration of DoWork()
would use the first value of _index
(in a way I didn't explain for the sake of simplicity), then the second iteration (the recursive call) would work with the second value _index
, and so on.
The reason why I'm asking this is because I'm getting a stack overflow exception after around 12 hours of running this app, and I believe it's because of the recursive calls.