Hi,

Is it OK to start at thread so it does its work, and just forget about it.
Will it automatically dissapear when it is done? For exampel, like this:

Thread t = new Thread(ReportingForm.StartProcessingReports);
t.SetApartmentState(ApartmentState.STA);
t.Start();

No Join or anything like that.

regards

Carl

Re: Start a thread and forget about it? by Jon

Jon
Tue Mar 04 02:59:28 CST 2008

Carl <ask@4it.com> wrote:
> Is it OK to start at thread so it does its work, and just forget about it.

Absolutely.

> Will it automatically dissapear when it is done? For exampel, like this:
>
> Thread t = new Thread(ReportingForm.StartProcessingReports);
> t.SetApartmentState(ApartmentState.STA);
> t.Start();
>
> No Join or anything like that.

Looks fine to me.

You might want to think about whether the thread should keep the
process alive if all the other foreground thread dies - if not, set
IsBackgroundThread to true.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Re: Start a thread and forget about it? by Carl

Carl
Tue Mar 04 03:18:33 CST 2008

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.22371fc069a5e748a34@msnews.microsoft.com...
> Carl <ask@4it.com> wrote:
>> Is it OK to start at thread so it does its work, and just forget about
>> it.
>
> Absolutely.
>
>> Will it automatically dissapear when it is done? For exampel, like this:
>>
>> Thread t = new Thread(ReportingForm.StartProcessingReports);
>> t.SetApartmentState(ApartmentState.STA);
>> t.Start();
>>
>> No Join or anything like that.
>
> Looks fine to me.
>
> You might want to think about whether the thread should keep the
> process alive if all the other foreground thread dies - if not, set
> IsBackgroundThread to true.
>

Great, and thanks for the tip about the IsBackgroundThread!