469,568 Members | 1,361 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Question related to threading concept.

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.

Mar 8 '06 #1
2 1305
archana wrote:
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].

Please clear my question related to threading.

Thanks in advance.

Mar 8 '06 #2
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.
--
HTH
Stoitcho Goutsev (100)
"archana" <tr**************@yahoo.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
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.

Mar 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Uwe Mayer | last post: by
5 posts views Thread by Richard P | last post: by
6 posts views Thread by rodchar | last post: by
reply views Thread by archana | last post: by
19 posts views Thread by frankiespark | last post: by
126 posts views Thread by Dann Corbit | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.