Timeout for the thread.
eg: assign 1 minutes to the thread, the thread could running for 2 minutes.
So when the timeout happen, the thread should terminate itself.
Can I do that? Thanks.
"100" <100@100.com> wrote in message
news:OqP48GifDH A.2356@TK2MSFTN GP12.phx.gbl...[color=blue]
> Timeout for what?
>
> B\rgds
> 100
>
>[/color]
Windows threads don't have this feature.
You have to implement this in the code that the thread executes.
B\rgds
100
"ll" <ll@hotmail.com > wrote in message
news:usZthKifDH A.460@TK2MSFTNG P12.phx.gbl...[color=blue]
> Timeout for the thread.
> eg: assign 1 minutes to the thread, the thread could running for 2[/color]
minutes.[color=blue]
> So when the timeout happen, the thread should terminate itself.
> Can I do that? Thanks.
>
> "100" <100@100.com> wrote in message
> news:OqP48GifDH A.2356@TK2MSFTN GP12.phx.gbl...[color=green]
> > Timeout for what?
> >
> > B\rgds
> > 100
> >
> >[/color]
>
>[/color]
Althought its specific to your software, you should
probably manage this from within the thread. Terminating
threads from outside can lead to leaked resources - even
in .Net where, for example you may have native handles
that require proper cleanup, or calls to make to IDispose
within .Net.
Perhaps you would set a time-to-live (TTL) value for your
thread before invoking it, and have the thread check and
dispose/cleanup gracefully? I would not recommend that
you rely on Timers for this.
Of course the thread cannot guarantee to be millisecond
precise, but at least you can set limits.
HTH,
mk
[color=blue]
>-----Original Message-----
>Timeout for the thread.
>eg: assign 1 minutes to the thread, the thread could[/color]
running for 2 minutes.[color=blue]
>So when the timeout happen, the thread should terminate[/color]
itself.[color=blue]
>Can I do that? Thanks.
>
>"100" <100@100.com> wrote in message
>news:OqP48GifD HA.2356@TK2MSFT NGP12.phx.gbl.. .[color=green]
>> Timeout for what?
>>
>> B\rgds
>> 100
>>
>>[/color]
>
>
>.
>[/color]
In some other thread (OThread) that knows about the thread (S_Thread) you
want to time out, you could, in OThread have the following C# code:
if (!S_Thread.Join (timeout)) //suspend this thread
(OThread) until S_Thread finishes, or timeout is
//reached
S_Thread.Abort( ); //S_Thread did not finish
during the timeout, so abort it.
or something similar.
"ll" <ll@hotmail.com > wrote in message
news:usZthKifDH A.460@TK2MSFTNG P12.phx.gbl...[color=blue]
> Timeout for the thread.
> eg: assign 1 minutes to the thread, the thread could running for 2[/color]
minutes.[color=blue]
> So when the timeout happen, the thread should terminate itself.
> Can I do that? Thanks.
>
> "100" <100@100.com> wrote in message
> news:OqP48GifDH A.2356@TK2MSFTN GP12.phx.gbl...[color=green]
> > Timeout for what?
> >
> > B\rgds
> > 100
> >
> >[/color]
>
>[/color]
you also need to catch for the abortexception inside the calling thread as
well for things to go smoothely. also, a thread is not guaranteed to honor
the threadabort exception in some cases that might be troublesome. after you
call abort in the calling thread you should then call join to wait on the
thread to abort.
"Fred Mellender" <nospamPlease_f redm@frontierne t.net> wrote in message
news:k5pab.2331 $Sr6.2298@news0 2.roc.ny...[color=blue]
> In some other thread (OThread) that knows about the thread (S_Thread) you
> want to time out, you could, in OThread have the following C# code:
> if (!S_Thread.Join (timeout)) //suspend this thread
> (OThread) until S_Thread finishes, or timeout is
> //reached
> S_Thread.Abort( ); //S_Thread did not[/color]
finish[color=blue]
> during the timeout, so abort it.
>
>
> or something similar.
>
>
> "ll" <ll@hotmail.com > wrote in message
> news:usZthKifDH A.460@TK2MSFTNG P12.phx.gbl...[color=green]
> > Timeout for the thread.
> > eg: assign 1 minutes to the thread, the thread could running for 2[/color]
> minutes.[color=green]
> > So when the timeout happen, the thread should terminate itself.
> > Can I do that? Thanks.
> >
> > "100" <100@100.com> wrote in message
> > news:OqP48GifDH A.2356@TK2MSFTN GP12.phx.gbl...[color=darkred]
> > > Timeout for what?
> > >
> > > B\rgds
> > > 100
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]
Comment