End function if it Takes too long

  • Thread starter Thread starter jr
  • Start date Start date
J

jr

I have an application the makes a call to a webservice to retrieve some
additional info for my app. The information I get back is
non-essential, so I do NOT want my entire app hanging to wait for this
repsonse if it takes more than, say, 2 seconds to a response from the
webserver.

Basically, how would I immediately end a function that is taking too
long to respond?
--
 
Actually, I'm really only interested in skipping/continuing on with my
application in the event that particular function takes more than a
specified amout of time to repsond.


My original thought was to set up a timer and that would call the sub
every 2 seconds, the first time through the sub, I set a boolean, if
the timer event fires againg and that boolean is set, it took too long
to execute so end the sub. This just seems wrong, and I can already
invision a couple of problems I might have implementing this strategy.
Thanks-

Humm... Have you tried the Timeout property before posting ???

Else elaborate a bit if you have a particular problem (what kind of
service (SOAP ?), do you call it synchronously or not ?)



--
 
jr,

You should use threading and a timer which set to off if you use the result
of the thread.

Cor
 
jr said:
I have an application the makes a call to a webservice to retrieve some
additional info for my app. The information I get back is
non-essential, so I do NOT want my entire app hanging to wait for this
repsonse if it takes more than, say, 2 seconds to a response from the
webserver.

Basically, how would I immediately end a function that is taking too
long to respond?
--
Have you thought of using a background worker to make this call?
 
Still a bit in the dark about your need but I do something like that.

I call xoap.something.weather.com every 15 minutes to get the latest
temp by ZIP for where the solar array is installed. If it runs, it
updates the ambient temp field. If it fails, so be it. I will try
again later. There seems to be a default timeout in he code. I am not
setting one but it will fail once or twice per week.

I do it in a different thread and the main program marches on. If the
temp eventually changes, the main thread will update the label field.
Else, it keeps using the old value until a new one comes along.

Sorry if this is no help. Just from personal experience.

Mike
 
Patrice,

Some people like to slow down their program by making a thread to let every
in fact synchonous operation to be managed by another process, they think
that the 1000 processors they have in their computers are only busy with
their program.

In this case I gave up to tell this in this case.

Cor
 
Sorry for being so vague in the original question. The webservice is
basically an xml uri that I send to the USPS in order to verify an
address a CS rep has entered into our sales app, it will return the
address formatted like the post office likes, again xml.

This service would be VERY nice to have. If something is way off with
the data, itll return an error msg (I can handle this no problem) but
we anticipate that there may be times when the service is taking too
long to respond, and we don't want to have them setting around waiting
on this part of the app.

So I've already built the dll to do all the xml request stuff, but I
also want to toss in this timer. I've been trying to work with
system.thread, but the main problem I'm having is not being able to
pass parameters to the thread - so I'm kinda stuck here. I've not
really done much with threading, and this seems to be such a broad
topic, so I really need a point to start from. Thanks-



Still a bit in the dark about your need but I do something like that.

I call xoap.something.weather.com every 15 minutes to get the latest
temp by ZIP for where the solar array is installed. If it runs, it
updates the ambient temp field. If it fails, so be it. I will try
again later. There seems to be a default timeout in he code. I am
not setting one but it will fail once or twice per week.

I do it in a different thread and the main program marches on. If the
temp eventually changes, the main thread will update the label field.
Else, it keeps using the old value until a new one comes along.

Sorry if this is no help. Just from personal experience.

Mike



--
 
yes, yes...so correct, many thanks. I didn't see this as an option
before because I was using the Webclient object, which doesn't have the
timeout property accesible (I least I didn't see it)

So I switched to the HttpWebRequest which does and It couldnt be
easier. Although at some point it would be handy to learn how to
accomplish what I originally wanted. Maybe some other time...

Thanks again Patrice!

Have you tried with a time out. IMO you do"nt have anothing special
to do, just set the timeout ot whatever you consider is the max you
can allow and it will timeout if the response doesn't come quick
enought...

Also web services can be called asynchronously out of the box so I
see whay you should handle this yourself...

You could easily test this by using a test service that would take
let 's say 10 s to respond. Then if you set the timoeut ot 8 or 20 s
it will or won't work... I assume that the timout is honored even
when calling the service asynchronously...



--
 
Back
Top