开发者

parralel ASP.NET Timer Controls

开发者 https://www.devze.com 2023-03-23 07:04 出处:网络
I have a problem and I\'d really appreciate a little help. On my .aspx I have four ASP.NET Timer Controls and when each of them Ticks I call asynchronously different web service method that returns m

I have a problem and I'd really appreciate a little help.

On my .aspx I have four ASP.NET Timer Controls and when each of them Ticks I call asynchronously different web service method that returns me some photos. I have a image in Update Panel and update it src when I get a photo. I'm using a jQuery lightBox plugin to preview a image.

The problem is that: I would like the Timers work in the same time (simultaneously). So on page Load, after some seconds should appear a Tick of each Timers (parallel, more less in the same time). Both Timers have the same time Interval so it should work, but in practice I've noticed that the second Timer ticks only after the first web service callback appears, and the third Timer ticks after the second web service callback appears. So it all works linearly, not parallel.

Any solutions how to modify it to Tick simultaneously ?

my .aspx:

<center>
    <asp:Timer runat="server" ID="UpdateTimer1" OnTick="UpdateTimer1_Tick" />
    <asp:UpdatePanel runat="server" ID="TimedPanel2" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="UpdateTimer1" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Literal runat="server" ID="Ltr1" />
            <div id="div1" runat="s开发者_如何转开发erver">
                <img alt="" id="img1" runat="server" style="width: 85%; height: 85%" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</center>    

one of my Timers in .aspx.cs, the rest of Timers is similar - the call different webservice, but have the same events, updateTimer_Ticks etc:

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
      {
         UpdateTimer1.Interval = 3000;
      {
}

protected void UpdateTimer1_Tick(object sender, EventArgs e)
{ 
   AsynchGetPhoto();       
}


public void AsynchGetPhoto()
{
    WS.Service Service = new WS.Service();

    Service.getPhotoCompleted += new Service.getPhotoCompletedEventHandler(PhotoCompleted);
    Service.getPhotoAsync();
}


public void PhotoCompleted(object sender, WS.Service.getPhotoCompletedEventArgs args)
{
    img1.Attributes.Add("src", "data:image/jpg;base64," + args.Result);
}


What i can tell you about your problem is my understanding about how this timer is working and happens behind the scene and you can investigate more in your code.

When the timers tick an asynchronous request to your function is done so each timer shall fire it's own request and the browser shall handle all the requests in parallel so i suggest that you open the firebug and see your timers requests and see if they are depending on each other and each request is handled after the other or it is just the rendering mechanism of the browser causing the timers to delay.

0

精彩评论

暂无评论...
验证码 换一张
取 消