Hi,
The problem is that the line -
this.Invoke(new MyDelegate(Function), args); // this = MainForm
is being called after the line -
terminatePopulate = true;
therefore I get an exception which states that MainForm has been
disposed when this.Invoke is called...
Is there a way to check if MainForm has been disposed. Perhaps theres
a better way of doing what am trying to achieve,
Thanks,
Aine
public class FormMain : Form
{
volatile bool terminatePopulate = false;
void FormMain_Load()
{
myThread = new System.Threading.Thread(MyThread());
myThread.Start();
}
void MyThread()
{
while (!anotherObject.ContinueWaiting)
{
if (!terminatePopulate)
this.Invoke(new MyDelegate(Function), args); // concerned
with control on Main Form
else
return;
Thread.Sleep(100); // Updates a control every 100 ms
}
if (!terminatePopulate)
this.Invoke(new MyOtherDelegate(Function), args);
}
private void OnClosing(object sender, EventArgs ev)
{
terminatePopulate = true;
}
}