Home All Groups Group Topic Archive Search About

Preventing ThreadAbortException.

Author
31 Jul 2006 8:17 PM
Ken Varn
Is there any method that I can guarantee execution of a code path within a
thread without a Thread.Abort call interrupting it?  I am concerned that a
file write that is done using two calls will not complete if the thread is
aborted before the second call gets a chance to complete.

I thought about setting the priority to highest for the critical calls, but
I was not sure if this would be sufficient or not.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Author
31 Jul 2006 8:36 PM
Carl Daniel [VC++ MVP]
"Ken Varn" <nospam> wrote in message
news:O5I2X5NtGHA.1504@TK2MSFTNGP03.phx.gbl...
> Is there any method that I can guarantee execution of a code path within a
> thread without a Thread.Abort call interrupting it?  I am concerned that a
> file write that is done using two calls will not complete if the thread is
> aborted before the second call gets a chance to complete.
>
> I thought about setting the priority to highest for the critical calls,
> but
> I was not sure if this would be sufficient or not.

You need a Constrained Execution Region.

http://msdn2.microsoft.com/en-us/library/ms228973(d=ide).aspx

There's a lot of subtlety and a lot of restrictions on using them, but
they're intended to provide a solution to exactly the kind of problem you're
describing.

-cd
Are all your drivers up to date? click for free checkup

Author
31 Jul 2006 8:49 PM
Greg Young
You can look at the safehandle class to see how this is done as well (I
believe it does just this).

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Show quoteHide quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:%23xwlyDOtGHA.1224@TK2MSFTNGP03.phx.gbl...
> "Ken Varn" <nospam> wrote in message
> news:O5I2X5NtGHA.1504@TK2MSFTNGP03.phx.gbl...
>> Is there any method that I can guarantee execution of a code path within
>> a
>> thread without a Thread.Abort call interrupting it?  I am concerned that
>> a
>> file write that is done using two calls will not complete if the thread
>> is
>> aborted before the second call gets a chance to complete.
>>
>> I thought about setting the priority to highest for the critical calls,
>> but
>> I was not sure if this would be sufficient or not.
>
> You need a Constrained Execution Region.
>
> http://msdn2.microsoft.com/en-us/library/ms228973(d=ide).aspx
>
> There's a lot of subtlety and a lot of restrictions on using them, but
> they're intended to provide a solution to exactly the kind of problem
> you're describing.
>
> -cd
>
>
Author
1 Aug 2006 8:40 PM
Ken Varn
What about 1.1 framework?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Show quoteHide quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:%23xwlyDOtGHA.1224@TK2MSFTNGP03.phx.gbl...
> "Ken Varn" <nospam> wrote in message
> news:O5I2X5NtGHA.1504@TK2MSFTNGP03.phx.gbl...
> > Is there any method that I can guarantee execution of a code path within
a
> > thread without a Thread.Abort call interrupting it?  I am concerned that
a
> > file write that is done using two calls will not complete if the thread
is
> > aborted before the second call gets a chance to complete.
> >
> > I thought about setting the priority to highest for the critical calls,
> > but
> > I was not sure if this would be sufficient or not.
>
> You need a Constrained Execution Region.
>
> http://msdn2.microsoft.com/en-us/library/ms228973(d=ide).aspx
>
> There's a lot of subtlety and a lot of restrictions on using them, but
> they're intended to provide a solution to exactly the kind of problem
you're
> describing.
>
> -cd
>
>
Author
31 Jul 2006 10:15 PM
Chris Mullins
"Ken Varn" <nospam> wrote in message
news:O5I2X5NtGHA.1504@TK2MSFTNGP03.phx.gbl...
> Is there any method that I can guarantee execution of a code path within a
> thread without a Thread.Abort call interrupting it?

The only option I know of is the BeginCriticalRegion stuff.

http://msdn2.microsoft.com/en-us/library/system.threading.thread.begincriticalregion.aspx


Bookmark and Share