DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 23 Aug 2007 00:16:53 GMT,    posted on: microsoft.public.dotnet.languages.vb        back       

Thread Index
  1    Gregory A Greenman w
          2    Gregory A Greenman w
                 3    ModelBuilder
          4    Cor Ligthert[MVP]
                 5    Gregory A Greenman w


Delaying Program Execution in a Loop   
I have a program that accesses a web service. One of the terms of 
use of this web service is that I am not supposed to call it more 
than about once per second. My program currently runs much too 
fast, so I need to add some sort of timer to bring it into 
compliance with their terms. Here's what my program looks like 
now:

Sub ProcessData
 While MoreData
  PrepareWebServiceRequest
  SubmitRequest
  ProcessWebServiceResponse
 End While
End Sub

I need to change this so that SubmitRequest waits until a second 
has elapsed since it last ran. Can someone tell me how I should 
do this?

Thanks.


-- 
Greg
----
http://www.spencerbooksellers.com
greg00 -at- spencersoft -dot- com
Date:Thu, 23 Aug 2007 00:16:53 GMT   Author:  

Re: Delaying Program Execution in a Loop   
In article , Gregory 
A Greenman <see@sig.below> declared...

> I have a program that accesses a web service. One of the terms of 
> use of this web service is that I am not supposed to call it more 
> than about once per second. My program currently runs much too 
> fast, so I need to add some sort of timer to bring it into 
> compliance with their terms. Here's what my program looks like 
> now:
> 
> Sub ProcessData
>  While MoreData
>   PrepareWebServiceRequest
>   SubmitRequest
>   ProcessWebServiceResponse
>  End While
> End Sub
> 
> I need to change this so that SubmitRequest waits until a second 
> has elapsed since it last ran. Can someone tell me how I should 
> do this?



I should add that I am using VB in VS.Net 2003.




-- 
Greg
----
http://www.spencerbooksellers.com
greg00 -at- spencersoft -dot- com
Date:Thu, 23 Aug 2007 00:21:18 GMT   Author:  

Re: Delaying Program Execution in a Loop   
If you are asking how to set up a timer event handler, then there should be 
plenty of examples on the web.  Usually though I would call the routine 
because I need to, not because I can.  

Is something in your client's state changing all the time that calling the 
webservice is necessary this frequently?  An example of this might be a model 
that needs to report home that it is a gps readout and here is where I am....

Is something in the webservice state changing that frequently that you need 
to call it so often?  An example of this would be that the webservice is the 
track of a FedEx package and you are trying to react to where to intercept 
your neighbor's goodie bag...

One of those questions should answer how often to call it.

"Gregory A Greenman" wrote:


> In article , Gregory 
> A Greenman <see@sig.below> declared...
> > I have a program that accesses a web service. One of the terms of 
> > use of this web service is that I am not supposed to call it more 
> > than about once per second. My program currently runs much too 
> > fast, so I need to add some sort of timer to bring it into 
> > compliance with their terms. Here's what my program looks like 
> > now:
> > 
> > Sub ProcessData
> >  While MoreData
> >   PrepareWebServiceRequest
> >   SubmitRequest
> >   ProcessWebServiceResponse
> >  End While
> > End Sub
> > 
> > I need to change this so that SubmitRequest waits until a second 
> > has elapsed since it last ran. Can someone tell me how I should 
> > do this?
> 
> 
> I should add that I am using VB in VS.Net 2003.
> 
> 
> 
> 
> -- 
> Greg
> ----
> http://www.spencerbooksellers.com
> greg00 -at- spencersoft -dot- com
> 
Date:Wed, 22 Aug 2007 19:46:01 -0700   Author:  

Re: Delaying Program Execution in a Loop   
Gregory,

Thread.sleep

Very simple, note that this is about your main thread, as it is a 
multithreading thread you have of course to use that.

http://msdn2.microsoft.com/en-us/library/system.threading.thread.sleep(VS.71).aspx

Cor

"Gregory A Greenman" <see@sig.below> schreef in bericht 
news:MPG.21368e44fce322b89896eb@news.verizon.net...

>I have a program that accesses a web service. One of the terms of
> use of this web service is that I am not supposed to call it more
> than about once per second. My program currently runs much too
> fast, so I need to add some sort of timer to bring it into
> compliance with their terms. Here's what my program looks like
> now:
>
> Sub ProcessData
> While MoreData
>  PrepareWebServiceRequest
>  SubmitRequest
>  ProcessWebServiceResponse
> End While
> End Sub
>
> I need to change this so that SubmitRequest waits until a second
> has elapsed since it last ran. Can someone tell me how I should
> do this?
>
> Thanks.
>
>
> -- 
> Greg
> ----
> http://www.spencerbooksellers.com
> greg00 -at- spencersoft -dot- com 
Date:Thu, 23 Aug 2007 05:33:03 +0200   Author:  

Re: Delaying Program Execution in a Loop   
In article , 
Cor Ligthert[MVP]  declared...

> 
> "Gregory A Greenman" <see@sig.below> schreef in bericht 
> news:MPG.21368e44fce322b89896eb@news.verizon.net...
> >I have a program that accesses a web service. One of the terms of
> > use of this web service is that I am not supposed to call it more
> > than about once per second. My program currently runs much too
> > fast, so I need to add some sort of timer to bring it into
> > compliance with their terms. Here's what my program looks like
> > now:
> >
> > Sub ProcessData
> > While MoreData
> >  PrepareWebServiceRequest
> >  SubmitRequest
> >  ProcessWebServiceResponse
> > End While
> > End Sub
> >
> > I need to change this so that SubmitRequest waits until a second
> > has elapsed since it last ran. Can someone tell me how I should
> > do this?



> Thread.sleep
> 
> Very simple, note that this is about your main thread, as it is a 
> multithreading thread you have of course to use that.
> 
> http://msdn2.microsoft.com/en-us/library/system.threading.thread.sleep(VS.71).aspx



Ahh, thank you very much. I was aware of thread.sleep, but while 
thinking about your answer, I see how thread.sleep can solve my 
problem.

My thinking had been that if I use thread.sleep, I'd slow my 
program down too much. If I sleep for 1.0 seconds, then the time 
from one call to the next will be 1.0 seconds plus the time it 
takes ProcessWebServiceResponse and PrepareWebSeviceRequest to 
execute. Depending on where I am in my program, those two 
procedures may take up a significant portion of the second by 
themselves. So, I'd be waiting too long.

However, on further thought, I can record the tickcount when I 
make the call. Then I use that and the current tickcount to 
figure out how long to sleep. So my code will look like this:


dim intTimeOfLastCall as integer = 0

Sub ProcessData
  While MoreData
    PrepareWebServiceRequest
    DelayCall
    SubmitRequest
    ProcessWebServiceResponse
  End While
End Sub

Sub DelayCall
  const DelayTime as integer = 1000

  if environment.tickcount < intTimeOfLastCall + DelayTime then
    thread.sleep(math.min(DelayTime, intTimeOfLastCall + 
DelayTime - environment.tickcount))
  endif

  intTimeOfLastCall = environment.tickcount
End Sub

Thanks again. I was going around in circles trying to figure out 
how to accomplish this and it turns out it was pretty easy.


-- 
Greg
----
http://www.spencerbooksellers.com
greg00 -at- spencersoft -dot- com
Date:Thu, 23 Aug 2007 05:13:45 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us