Multi Threaded App - Stack Trace Error

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();
}

}
 
S

Simon

Hey,

Just out of curiosity did you deliberately try and obfuscate certain
class and variables names, or do you actually have variables like 'iF',
'iT' and 'L' and classes like 'LH'?

e.g.
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;

Just curious...

Thanks

'S'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top