G
Guest
I have a multi threaded app that runs fine 99 percent of the time. However,
sporadically, I receive error {Cannot evaluate expression because the
current thread is in a stack overflow state.} at different spots in the
code. Random lines of code seem to generate this error, never the same line
twice so far. The threading is defined like so... I'm hoping that there may
be a way to accomplish the same threading and without generating this
sporadic error... Any thoughts would be greatly appreciated. I have removed
most code for readability.
public partial class Form1 : Form
{
private LH[] LA;
LH lh = new LH();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int iF = 0;
int iT = 7;
LA = new LH[iT - iF + 1];
for (int iTr = iF; iTr <= iT; iTr++)
{
LH L = new LH();
LA[iTr - iF] = L;
L.iTr = iTr;
ThreadStart ts = new ThreadStart(L.ProcessingThread);
Thread wrkThread = new Thread(ts);
wrkThread.SetApartmentState(ApartmentState.STA);
wrkThread.Name = iTr.ToString();
wrkThread.Start();
}
return;
}
public class LH
{
static readonly object countLock = new object();
public void ProcessingThread()
{
try
{
lock (countLock)
{
//
}
}
catch (COMException e)
{
//
}
catch (Exception e)
{
//
}
Application.Run();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
sporadically, I receive error {Cannot evaluate expression because the
current thread is in a stack overflow state.} at different spots in the
code. Random lines of code seem to generate this error, never the same line
twice so far. The threading is defined like so... I'm hoping that there may
be a way to accomplish the same threading and without generating this
sporadic error... Any thoughts would be greatly appreciated. I have removed
most code for readability.
public partial class Form1 : Form
{
private LH[] LA;
LH lh = new LH();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int iF = 0;
int iT = 7;
LA = new LH[iT - iF + 1];
for (int iTr = iF; iTr <= iT; iTr++)
{
LH L = new LH();
LA[iTr - iF] = L;
L.iTr = iTr;
ThreadStart ts = new ThreadStart(L.ProcessingThread);
Thread wrkThread = new Thread(ts);
wrkThread.SetApartmentState(ApartmentState.STA);
wrkThread.Name = iTr.ToString();
wrkThread.Start();
}
return;
}
public class LH
{
static readonly object countLock = new object();
public void ProcessingThread()
{
try
{
lock (countLock)
{
//
}
}
catch (COMException e)
{
//
}
catch (Exception e)
{
//
}
Application.Run();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}