Question related to threading concept.

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.
 
J

Jianwei Sun

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].
 
S

Stoitcho Goutsev \(100\)

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.
 

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

Similar Threads

A More Effecient Threading? 4
Threading 8
Threading - newbie question 9
Using Multi threading 1
Threading question 7
.NET Threading Question 17
Threading and Instances 6
Threading a server 8

Top