473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Threading Timeout Question

Hello!

I have a question that I really can’t think of an answer for, but thought I
might as well give a shot here. I have a web service, created by the VS web
service creator. I have another class, clsWebservice, which provides easy
asynchronous access to each method in the web service. However, the problem
is sometimes a web service call might be dropped, and I want to watch for
that, with a timeout to tell the user that there’s a problem, and ask if he
wants to reissue the request. How would I do the timeout? The easiest answer
would seem to be the AsyncWaitHandle.WaitOne, with a timeout, but that stops
my main thread, so it can’t refresh during that time, and to the user, it
would look like it’s locking up. However, I also couldn’t find a way to start
a thread, and pass parameters through it to a function, to pass to the web
service, which would be ideal – because then it wouldn’t matter if I locked
up that thread.

I apologize; I am rather new at threading.

God bless,

Jose
Nov 17 '05 #1
2 1585
JMax <JM**@discussions.microsoft.com> wrote:
I have a question that I really can?t think of an answer for, but thought I
might as well give a shot here. I have a web service, created by the VS web
service creator. I have another class, clsWebservice, which provides easy
asynchronous access to each method in the web service. However, the problem
is sometimes a web service call might be dropped, and I want to watch for
that, with a timeout to tell the user that there?s a problem, and ask if he
wants to reissue the request. How would I do the timeout? The easiest answer
would seem to be the AsyncWaitHandle.WaitOne, with a timeout, but that stops
my main thread, so it can?t refresh during that time, and to the user, it
would look like it?s locking up. However, I also couldn?t find a way to start
a thread, and pass parameters through it to a function, to pass to the web
service, which would be ideal ? because then it wouldn?t matter if I locked
up that thread.

I apologize; I am rather new at threading.


You could start a timer on your main thread, as an option. For how to
effectively pass parameters, see
http://www.pobox.com/~skeet/csharp/t...rameters.shtml

(You might want to read the rest of the article for general threading
help.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
JMax wrote:
However, the problem is sometimes a web service
call might be dropped, and I want to watch for that, with a timeout
to tell the user that there's a problem, and ask if he wants to
reissue the request. How would I do the timeout? [...] However, I also
couldn't find a way to start a thread, and pass parameters through
it to a function, to pass to the web service [...]


Hi Jose. Probably the best way to do this is using a System.Threading.Timer
object. You can specify a time and a callback function and a threadpool
thread will invoke your callback after the given amount of time has passed.
The TimerCallback delegate takes a state object that allows you to pass data
to the callback, but this isn't strictly necessary; it's always possible to
create a temporary object which holds both the data and the callback. This
is how you can get data to a new thread - just create an object, passing
some data to its constructor, and then call a "Run" or "Start" method on
that object which invokes Thread.Start() on one of its own methods. I hope
this helps.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included code samples are subject to the terms
specified at http://www.microsoft.com/info/cpyright.htm
Nov 17 '05 #3

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

Similar topics

1
by: Rune Hansen | last post by:
select(0, NULL, NULL, NULL, {0, 8000}) = 0 (Timeout) futex(0x822f530, FUTEX_WAKE, 1) = 0 gettimeofday({1075823054, 603000}, NULL) = 0 futex(0x822f530, FUTEX_WAKE, 1) = 0...
0
by: elcinturapartida | last post by:
Hello all, I am not sure if this question is about threading or serial i/o - it has elements of both. I'm on WinXP (desktop) and WinNT (labtop), when I run miniterm.py there is no problem both...
5
by: Tuvas | last post by:
Is there a way to stop a thread with some command like t.stop()? Or any other neat way to get around it? Thanks!
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
6
by: whtinkm | last post by:
Hi, All Recently, my project need some code like following: using System; using System.Threading; namespace MyTimerTest { class Class1 {
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
2
by: KSC | last post by:
Hello, I have used a thread timer as in the documentation on MSDN in my VB.NET application. Using System.Threading.Interlocked.Increment I increment the counter to a certain point, perform an...
4
by: JimD | last post by:
Is this safe? Any pitfalls? I have done threading in regular C# apps, but haven't had a needs to do threading in ASP.Net, until now. The issue I have ran into is this: Our corporate portal...
5
by: Giulio Petrucci | last post by:
Hello everybody, I'm quite new to .NET FW programming, and I started just few months ago, on FW2.0, knowing actually _nothing_ about FW1.1, so my question may sound silly... Anyway, what I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.