PC Review


Reply
Thread Tools Rate Thread

How to deal with this thread?

 
 
Andrew
Guest
Posts: n/a
 
      10th Jul 2008
Hello, friends,

In my app, after a user selects a document, I create a new thread to print
this document so that this user may continue to do his/her work.

Thread thread = new Thread(new
ThreadStart(bulkPrint.bulkPrint));
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();

I currently leave this thread like this without explicitly terminate it.

I don't feel right since I think it should be terminated somehow.

What should I do and how? Thanks a lot!
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      10th Jul 2008
Andrew <(E-Mail Removed)> wrote:
> In my app, after a user selects a document, I create a new thread to print
> this document so that this user may continue to do his/her work.
>
> Thread thread = new Thread(new
> ThreadStart(bulkPrint.bulkPrint));
> thread.SetApartmentState(ApartmentState.STA);
> thread.IsBackground = true;
> thread.Start();
>
> I currently leave this thread like this without explicitly terminate it.
>
> I don't feel right since I think it should be terminated somehow.
>
> What should I do and how? Thanks a lot!


Why do you feel you need to terminate it? If it finishes on its own, it
will go away. If there are only background threads left in the process,
the process will die.

Why do you want to kill it?

--
Jon Skeet - <(E-Mail Removed)>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      10th Jul 2008
If this thread can go away by itself, that is great.

One reason I think it should be explicitely terminated is that I got the
following message which I have never had before creating this thread:

COM object that has been separated from its underlying RCW cannot be used"
exception within threads

"Jon Skeet [C# MVP]" wrote:

> Andrew <(E-Mail Removed)> wrote:
> > In my app, after a user selects a document, I create a new thread to print
> > this document so that this user may continue to do his/her work.
> >
> > Thread thread = new Thread(new
> > ThreadStart(bulkPrint.bulkPrint));
> > thread.SetApartmentState(ApartmentState.STA);
> > thread.IsBackground = true;
> > thread.Start();
> >
> > I currently leave this thread like this without explicitly terminate it.
> >
> > I don't feel right since I think it should be terminated somehow.
> >
> > What should I do and how? Thanks a lot!

>
> Why do you feel you need to terminate it? If it finishes on its own, it
> will go away. If there are only background threads left in the process,
> the process will die.
>
> Why do you want to kill it?
>
> --
> Jon Skeet - <(E-Mail Removed)>
> Web site: http://www.pobox.com/~skeet
> Blog: http://www.msmvps.com/jon_skeet
> C# in Depth: http://csharpindepth.com
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      10th Jul 2008
Andrew <(E-Mail Removed)> wrote:
> If this thread can go away by itself, that is great.
>
> One reason I think it should be explicitely terminated is that I got the
> following message which I have never had before creating this thread:
>
> COM object that has been separated from its underlying RCW cannot be used"
> exception within threads


That sounds like it's to do with what you're doing *on* the thread -
which would depend on what "bulkPrint" is. Unfortunately I'm not
terribly hot on COM...

--
Jon Skeet - <(E-Mail Removed)>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
 
Reply With Quote
 
Ciaran O''Donnell
Guest
Posts: n/a
 
      11th Jul 2008
From reading around online. It looks like this might be caused by you not
releasing your COM object properly by Disposing them. Check that you have
correctly released any objects and explicitly called Dispose on the COM
objects/wrappers you are using before the thread finishes.

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


"Andrew" wrote:

> If this thread can go away by itself, that is great.
>
> One reason I think it should be explicitely terminated is that I got the
> following message which I have never had before creating this thread:
>
> COM object that has been separated from its underlying RCW cannot be used"
> exception within threads
>
> "Jon Skeet [C# MVP]" wrote:
>
> > Andrew <(E-Mail Removed)> wrote:
> > > In my app, after a user selects a document, I create a new thread to print
> > > this document so that this user may continue to do his/her work.
> > >
> > > Thread thread = new Thread(new
> > > ThreadStart(bulkPrint.bulkPrint));
> > > thread.SetApartmentState(ApartmentState.STA);
> > > thread.IsBackground = true;
> > > thread.Start();
> > >
> > > I currently leave this thread like this without explicitly terminate it.
> > >
> > > I don't feel right since I think it should be terminated somehow.
> > >
> > > What should I do and how? Thanks a lot!

> >
> > Why do you feel you need to terminate it? If it finishes on its own, it
> > will go away. If there are only background threads left in the process,
> > the process will die.
> >
> > Why do you want to kill it?
> >
> > --
> > Jon Skeet - <(E-Mail Removed)>
> > Web site: http://www.pobox.com/~skeet
> > Blog: http://www.msmvps.com/jon_skeet
> > C# in Depth: http://csharpindepth.com
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Has anyone made a Deal or No Deal Gamebord kajunlion@yahoo.com Microsoft Excel Misc 2 17th Apr 2008 12:12 AM
ShowDialog - Cross-thread operation not valid: Control'CheckAccountInfo' accessed from a thread other than the thread it was createdon. Tom C Microsoft C# .NET 9 20th Feb 2008 08:15 PM
AMD64 or Semperon, deal or no deal? Tad Confused Computer Hardware 13 13th Apr 2006 06:43 PM
Maybe we should start a thread on best AMD processor deal since everyones saying they are locking the AMD 2500 Bartons John Computer Hardware 3 9th Nov 2003 09:50 PM
Re: Is this 181 GB drive on EBay a good deal or a bad deal? GMAN Storage Devices 0 24th Jun 2003 08:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.