I do my first tries in c#. In my application a new Fom is created to show some measurements. i do this in a thread. on form closing i will exit the thread. sometimes it throws a ObjectDisposedException exception. i tried to handle it with a mutex. but then i have a dead lock.
private void FormClosing(object sender, FormClosingEventArgs e)
{
m_mutClosing.WaitOne();
bDoWork = false;
m_mutClosing.ReleaseMutex();
}
public void DoWork()
{
while (bDoWork)
{
i++;
m_mutClosing.WaitOne();
this.Invoke((MethodInvoker)delegate()
{
if(textBox != null)
textBox.Text = i.ToString();
});
m_mutClosing.ReleaseMutex();
Thread.Sleep(500);
}
MessageBox.Show("end thread");
}
the problem seems like i try to write a value to the textbox until the objects get removed.
I don´t see the solution in the other question, can please someone explain?