T
TT \(Tom Tempelaere\)
Hi people,
This is a question on the use of Thread.Interrupt. I would love to hear from
anyone who ever used the Interrupt method on a thread to unblock it.
My C# book sais that Interrupt method will interrupt a wait, sleep or join
performed on the thread.
Now suppose that I'm coding a DB app using C#, and that the data queries run
on a sperate thread. The queries take a long time to execute, and I need a
way to unblock the thread. Would Thread.Interrupt unblock the thread, i.e.
will the underlying implementation of ADO.NET use WaitHandle's? (I assume
ADO.NET is the way to code DB apps.)
Perhaps that is a bad example because it depends on the implementation of
ADO.NET, and I don't even know ADO.NET yet. My intent with Thread.Interrupt
is to use it in my (base) thread class as a general way to unblock it. But I
have my doubts if I can use it for that in all cases.
I'm thinking of not using Thread.Interrupt in my base class, and allow the
derived class to do the Thread.Interrupt when it deems necessary. Seems like
safest and most flexible. Comments?
Thanks,
PS: The book also mentions that I should avoid relying on Thread.Interrupt
to unblock a thread. It mentions problems with unmanaged code executed via
interop (will not unlock), and the fact that it won't unblock
Thread.SpinWait. Any other good reasons why I shouldn't?
PS2: A different Question: does ADO.NET provide an explicit way to cancel a
long running query (or call, ...)?
This is a question on the use of Thread.Interrupt. I would love to hear from
anyone who ever used the Interrupt method on a thread to unblock it.
My C# book sais that Interrupt method will interrupt a wait, sleep or join
performed on the thread.
Now suppose that I'm coding a DB app using C#, and that the data queries run
on a sperate thread. The queries take a long time to execute, and I need a
way to unblock the thread. Would Thread.Interrupt unblock the thread, i.e.
will the underlying implementation of ADO.NET use WaitHandle's? (I assume
ADO.NET is the way to code DB apps.)
Perhaps that is a bad example because it depends on the implementation of
ADO.NET, and I don't even know ADO.NET yet. My intent with Thread.Interrupt
is to use it in my (base) thread class as a general way to unblock it. But I
have my doubts if I can use it for that in all cases.
I'm thinking of not using Thread.Interrupt in my base class, and allow the
derived class to do the Thread.Interrupt when it deems necessary. Seems like
safest and most flexible. Comments?
Thanks,
PS: The book also mentions that I should avoid relying on Thread.Interrupt
to unblock a thread. It mentions problems with unmanaged code executed via
interop (will not unlock), and the fact that it won't unblock
Thread.SpinWait. Any other good reasons why I shouldn't?
PS2: A different Question: does ADO.NET provide an explicit way to cancel a
long running query (or call, ...)?