Question related to threading concept.

  • Thread starter Thread starter archana
  • Start date Start date
A

archana

Hi all,

I don't have much of knowledge about threading.

I have on .net application where in main i am starting one secondary
thread.

like


public class yyy

{

public void abc()
{
for ( int i = 0; i<=3;i++)
{
System.Console.Write(i + " ");
Thread.Sleep(1);
}
}
}

in form i have code as below on one button

yyy a = new yyy();
Thread t = new Thread(new ThreadStart(a.abc));
t.Start();
Console.WriteLine("complete");
this.Close();
return;


So my question is when i am running one thread which is doing some
heavy processing and mymain application is closing on button click will
it close after secondary thread completes processing or it will close
immediately by keeping second thread running in system.

One more question is what is application.exitthread doing?

Please clear my question related to threading.

Thanks in advance.
 
archana said:
Hi all,

I don't have much of knowledge about threading.

I have on .net application where in main i am starting one secondary
thread.

like


public class yyy

{

public void abc()
{
for ( int i = 0; i<=3;i++)
{
System.Console.Write(i + " ");
Thread.Sleep(1);
}
}
}

in form i have code as below on one button

yyy a = new yyy();
Thread t = new Thread(new ThreadStart(a.abc));
t.Start();
Console.WriteLine("complete");
this.Close();
return;


So my question is when i am running one thread which is doing some
heavy processing and mymain application is closing on button click will
it close after secondary thread completes processing or it will close
immediately by keeping second thread running in system.

[It will close immediately, one way to handle this is you have to wait
on some event to wait for the second thread to complete the work. In the
working thread, you set this event when the work completes].
One more question is what is application.exitthread doing?
[I think you can look it up in MSDN].
 
archana,

The process terminates only after all threads running inside finish. When
you terminate the main UI thread the framework will terminate all worker
threads that have IsBackground property set to *true*. All others
IsBackground = false will keep running, thus keep the process alive.

So if you want your UI thread to be survived by the worker thread you set
the worker thread's IsBackground = false and vice versa.
 
Back
Top