473,473 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Thread timeout?

ll
Hi,
How to specify the timeout value(ms) for a thread?
Thanks.
Nov 15 '05 #1
6 19364
100
Timeout for what?

B\rgds
100
Nov 15 '05 #2
ll
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" <10*@100.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
Timeout for what?

B\rgds
100

Nov 15 '05 #3
100
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:us*************@TK2MSFTNGP12.phx.gbl...
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" <10*@100.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
Timeout for what?

B\rgds
100


Nov 15 '05 #4
mk
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
-----Original Message-----
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" <10*@100.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
Timeout for what?

B\rgds
100

.

Nov 15 '05 #5
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:us*************@TK2MSFTNGP12.phx.gbl...
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" <10*@100.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
Timeout for what?

B\rgds
100


Nov 15 '05 #6
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" <no****************@frontiernet.net> wrote in message
news:k5*****************@news02.roc.ny...
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:us*************@TK2MSFTNGP12.phx.gbl...
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" <10*@100.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
Timeout for what?

B\rgds
100



Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
4
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with...
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
1
by: Graham | last post by:
Hi, I have web based email management system where a user can login, create an email and then send it to multiple recipients. The email component I use generates all of the physical .eml files...
4
by: JeffSinNHUSA via DotNetMonster.com | last post by:
Hi, I have a long running task that I want to run on a regular basis to do some db updates. I can't write a windows service because it is being hosted elsewhere. I want to run this task within...
22
by: Nick Craig-Wood | last post by:
Did anyone write a contextmanager implementing a timeout for python2.5? I'd love to be able to write something like with timeout(5.0) as exceeded: some_long_running_stuff() if exceeded:...
3
by: Kevin | last post by:
Hi! Is there anyway to set a timeout for a Thread? Regards!
1
by: Chrace | last post by:
Hi all, I have a problem with with Thread.Join( Timeout ) where the timeout never occurs. I basically need to make a connection to an AS400 box which works fine. Once in a blue moon the AS400...
3
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.