[RESOLVED] [VS2005] Threading
I have a program that is running multiple threads at the same time. The maximum amount of threads is a user-changeable option. I was doing some testing on this and after a certain amount of threads have been called, I get a System.OutOfMemoryException.
I have a program I created in Visual Studio 2003 that never had this problem, it did pretty much what this application is doing, and it doesn't give me that error with even more threads being called than my current application.
I know they have changed a few of the threading things with the new 2.0 Framework, I was wondering if they made a max limit of sorts also?
I guess, my questions are...
1) What is the correct way to start a thread?
2) Do I need to close/dispose the thread in some way? (An example of this would be helpful if this is the case).
Here is the code I am using, and where the error occurs.
lbox is an arraylist of values that need calculated.
threadParamClass is a class I made to pass parameters via thread.
The thread can access the parameters passed this way.
PHP Code:
for (int x = 0; x <= thecount; x++)
{
Application.DoEvents();
gu = null;
mythread = null;
gu = new threadParamClass(f1, this, x,lbox[0].ToString());
mythread = new Thread(new ThreadStart(gu.Calculate));
mythread.IsBackground = true;
mythread.Start(); //out of memory here
cint++;
f1.textStat.Text = x + "\\" + thecount;
lbox.RemoveAt(0);
if (cint == 100)
{
manResetEvt.Reset();
manResetEvt.WaitOne(500000, false);
}
}