Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2005

Tip: Looking for answers? Try searching our database.

Web Service Polling

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shane - 20 Dec 2005 21:37 GMT
I have a particular requirement when I call a web service; I have to call the
web service, wait until the web service returns or my timeout expires
(whichever is sooner) and exit.

I tried to use the MSDN example to poll a web service and abort it after a
specified timeout.
Have a look at the code below:

/* Set the timeout in seconds*/
int Timeout = 20;

/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;

/* The SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
IAsyncResult ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (ar.IsCompleted == false)
{
  DateTime elapsed = DateTime.Now;
  TimeSpan ts = elapsed - start;
  if (ts.TotalSeconds > Timeout )
  {
      WS.Abort();
  }
}

---

What I have found is that the code snippet does not behave as expected, ie
the IsCompleted flag NEVER gets set to true, even though I know that the web
service call has completed. It just loops for ever in the while loop until
the the abort statement gets called.

Any help would be appreciated.
Signature

Regards
----------------
Shailen Sukul
MCSD MCAD

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein

Michael Nemtsev - 20 Dec 2005 21:48 GMT
Hello Shane,

Hope this heps: http://www.yoda.arachsys.com/csharp/threads/volatility.shtml

S> I have a particular requirement when I call a web service; I have to
S> call the web service, wait until the web service returns or my
S> timeout expires (whichever is sooner) and exit.
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Shane - 20 Dec 2005 22:14 GMT
I tried locking the object as follows, alas to no avail:

static IAsyncResult ar;
static readonly object stopLock = new object();

static bool IsCompleted
{
   get
    {
       lock (stopLock)
       {
           return ar.IsCompleted;
       }
    }
}
/* Set the timeout in seconds*/
int Timeout = 20;

/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;

/* The SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (IsCompleted == false)
{
  DateTime elapsed = DateTime.Now;
  TimeSpan ts = elapsed - start;
  if (ts.TotalSeconds > Timeout )
  {
      WS.Abort();
      break;
  }
}

Signature

Regards
----------------
Shailen Sukul
MCSD.Net MCSD MCAD

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein

> Hello Shane,
>
[quoted text clipped - 9 lines]
> "At times one remains faithful to a cause only because its opponents do not
> cease to be insipid." (c) Friedrich Nietzsche
Shane - 20 Dec 2005 21:50 GMT
sorry need to ensure that break was called after abort.

/* Set the timeout in seconds*/
int Timeout = 20;

/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;

/* The SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
IAsyncResult ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (ar.IsCompleted == false)
{
  DateTime elapsed = DateTime.Now;
  TimeSpan ts = elapsed - start;
  if (ts.TotalSeconds > Timeout )
  {
      WS.Abort();
      break;
  }
}

Signature

Regards
----------------
Shailen Sukul
MCSD.Net MCSD MCAD

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.