Threading problem in c#.net
t = new Thread(new ThreadStart(picsend));
t.IsBackground.CompareTo(true);
t.Start();
Hi, I am running Thread like this using this server prog receives video stream from the client program
if first client prog is started and then server prog is started the no problem occuring
if i start the server first and closed the server and then again if i start the server then it is giving
A PROBLEM IS ENCOUNTERED AND NEEDS TO CLOSE
THEN i am going to ctrl+alt+del(windows task manager ) and killing the server process every time
how to avoid this problem
iam aborting the thread in form close event llike bellow
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
t.Abort();
}
Dushan StankovicPosted Sep 21, 2009, 4:10 PM
t.IsBackground.CompareTo(true); CompareTo method don't change value of the prop IsBackgroud, just Compare values.
you must set value: t.IsBackground = true; and that thread will be background thread.
I will propose you to do check in Dispose method in IDisposed implemetation of your class, if you have it, and stop thread if still running.
Danatas GerviPosted Sep 21, 2009, 1:07 PM
The abort is the worse way to stop the thread. This is the last way.
You should write your picsend delegate so, that it will stop working and exit from main loop (or something) by return; operator.
The is various way to do it – for example –
Shared bolean variable, flag "DoSend" – and main form in form closing event can set it to false, and while(DoSend) {} in thread will end its loop and will exit.
Also, do not forget to close unmanaged resources…
Deepak BhatiaPosted Sep 21, 2009, 8:49 AM