471,306 Members | 1,276 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Creating a timeout

I have a webservice which takes a hostname and drive letter as input and
returns the free space for that drive on that host as a long. Sometimes
it will take forever to get information from a recalcitrant host, but it
keeps trying far longer than I want it to. How can I set up a timeout
for the process, so that after a couple of seconds it returns a failure
status and gives up waiting?

Currently, the method maps the drive, finds its available space, and
then unmaps it, which all works quite neatly. If the host doesn't exist
or the drive doesn't exist it returns -1. Otherwise it returns the free
space in bytes as a long. We're currently experiencing network
difficulties because of a relocation. Most of our important business
systems, including DNS servers and the like, are now about 10 miles away
and are accessed via a much, much slower link than we're used to. Some
hosts simply take ages to respond and I'd like to impose a timeout
somehow. I thought maybe some sort of timer based arrangement might
work, but now that I'm trying it I can't actually work out what needs to
be done.

Any help would be appreciated.
*** Sent via Developersdex http://www.developersdex.com ***
Dec 22 '05 #1
3 1992
There is a parameter on the Machine.Config file (or you can put it on your
Web.Config file to affect only your website) called@

httpRuntime, attribute : executionTimeout= (in seconds)
Ex:
<system.web>
<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100"
enableVersionHeader="true"/>
<system.web>

This will timeout after 90 seconds

Cheers

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Adam Short" wrote:
I have a webservice which takes a hostname and drive letter as input and
returns the free space for that drive on that host as a long. Sometimes
it will take forever to get information from a recalcitrant host, but it
keeps trying far longer than I want it to. How can I set up a timeout
for the process, so that after a couple of seconds it returns a failure
status and gives up waiting?

Currently, the method maps the drive, finds its available space, and
then unmaps it, which all works quite neatly. If the host doesn't exist
or the drive doesn't exist it returns -1. Otherwise it returns the free
space in bytes as a long. We're currently experiencing network
difficulties because of a relocation. Most of our important business
systems, including DNS servers and the like, are now about 10 miles away
and are accessed via a much, much slower link than we're used to. Some
hosts simply take ages to respond and I'd like to impose a timeout
somehow. I thought maybe some sort of timer based arrangement might
work, but now that I'm trying it I can't actually work out what needs to
be done.

Any help would be appreciated.
*** Sent via Developersdex http://www.developersdex.com ***

Dec 22 '05 #2
One idea would be to use different threads. Currently I'm working in
1.1, but I know the 2.0 framework has a read timeout on a socket. To
get that same functionality, I perform the read in a seperate thread,
use a flag to determine if it has completed or if it's still blocking,
and monitor that for x milliseconds. If the time passes and the method
is still blocking I just kill the thread. It's rather complicated and
probably a little dangerous, so I would make sure that you have a firm
understanding of threads in .NET.

If this sounds like something you would like to try and you would like
to see some code let me know. Hope this helps ~ Justin

Dec 22 '05 #3
Hi Justin,

It will not work on a webservice environment, if I call a function
asynchronicly on a webservice and you start the reading in another thread the
function will never return anything, what is more, you should never abort a
thread (you can not kill it otherwise), it is considered bad practice and
will raise an exception. In order to do what you want you should use the same
thread where the calling come from and use the Monitor.Enter function with a
explicit timeout, but is not recommended in this scenario.

Hope this helps to enhance the threads experience.
Regards

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Justin Creasy" wrote:
One idea would be to use different threads. Currently I'm working in
1.1, but I know the 2.0 framework has a read timeout on a socket. To
get that same functionality, I perform the read in a seperate thread,
use a flag to determine if it has completed or if it's still blocking,
and monitor that for x milliseconds. If the time passes and the method
is still blocking I just kill the thread. It's rather complicated and
probably a little dangerous, so I would make sure that you have a firm
understanding of threads in .NET.

If this sounds like something you would like to try and you would like
to see some code let me know. Hope this helps ~ Justin

Dec 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by E Sullivan | last post: by
1 post views Thread by Ken | last post: by
4 posts views Thread by DavidS | last post: by
22 posts views Thread by Nick Craig-Wood | last post: by
25 posts views Thread by =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post: by
13 posts views Thread by LordHog | last post: by
2 posts views Thread by JimLad | last post: by
reply views Thread by rosydwin | last post: by

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.