Thread doesn't die

  • Thread starter ns leonardo via .NET 247
  • Start date
N

ns leonardo via .NET 247

Hello,

I am using p/Invoke to access a card reader device's dll and
I am using a thread to emulate a assync call from a sync call.
Whe I want to read a card, I start a new thead that makes a blocking call
while my application can continue. When the card is read the thread finishes.

But when the operation is canceled I have to kill the thread and it doesn't die.
I've tried to use Abort(), Suspend() and to turn the thread a background thread but it doesn't work.

I thing the thread doesn't die because it's blocked waiting the card.
Is there a way to force this therad to die?

Can somebody helpe me?
 
J

Jonathan Allen

Try contacting the card reader's manufacturer. If they were nice, they have
a version of the call that times-out.

I cannot think of a way to abort the thread as long as its in non-CLR land,
the runtime has no way to know when it is safe to do so.
 
D

David Levine

As the OP said, you cannot kill a thread while it is running in unmanaged
code. But....you can try running the thread from another appdomain. When you
need to stop the thread you can unload the appdomain - the runtime goes to
great lengths to kill threads that originate in other appdomains. Don't know
if it will work but it should be easy enough to test.
 

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

Top