How to deal with this thread?

A

Andrew

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

Jon Skeet [C# MVP]

Andrew said:
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?
 
A

Andrew

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
 
J

Jon Skeet [C# MVP]

Andrew said:
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...
 
C

Ciaran O''Donnell

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.
 

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


Top