Table of Contents
  • Getting Started
  • EO.Pdf
  • EO.Web
    • Overview
    • Installation & Deployement
    • EO.Web ToolTip
    • EO.Web Rating
    • EO.Web Slider & RangeSlider
    • EO.Web ListBox
    • EO.Web ComboBox
    • EO.Web Captcha
    • EO.Web ASPX To PDF
    • EO.Web Slide
    • EO.Web Flyout
    • EO.Web EditableLabel
    • EO.Web ImageZoom
    • EO.Web Floater
    • EO.Web Downloader
    • EO.Web ColorPicker
    • EO.Web HTML Editor
    • EO.Web File Explorer
    • EO.Web SpellChecker
    • EO.Web Grid
    • EO.Web MaskedEdit
    • EO.Web Splitter
    • EO.Web Menu
    • EO.Web Slide Menu
    • EO.Web TabStrip
    • EO.Web TreeView
    • EO.Web Calendar
    • EO.Web Callback
    • EO.Web MultiPage
    • EO.Web Dialog
    • EO.Web AJAXUploader
    • EO.Web ProgressBar - Free!
    • EO.Web ToolBar - Free!
  • EO.WebBrowser
  • EO.Wpf
  • Common Topics
  • Reference
Moving Progress Bar (Server Side)

Overview

A ProgressBar can be associated with a server side task and updates accordingly when the server side task progresses.

The following table lists the most important properties/events related to this feature:

Property/Event Remarks
StartTaskButton ID of the button to start server side task.
StartTaskButton ID of the button to stop server side task.
RunTask Server side event handler that runs the task.

Getting Started

The following section describes hows a server side task is carried out through a ProgressBar control:

  1. A server side task can be started by user clicking StartTaskButton or via a client side Javascript call to the ProgressBar's startTask method;
  2. The ProgressBar raises server side event RunTask. You should perform your long running task inside this handler. While running the task, your code should frequently:
    • Checks whether the task has been stopped via ProgressTaskEventArgs.IsStopped. This property is updated when the task has been stopped from the client side, either by user clicking StopTaskButton or call stopTask programmmatically;
    • Calls ProgressTaskEventArgs.UpdateProgress to update progress information. Information passed to this function will be passed to the client side to update the progress bar;
  3. A stop notification is sent to the server when one of the following occurs:
    • End user clicks StopTaskButton, or
    • stopTask is called, or
    • End user navigates to another page thus causes the current page to be unloaded;

    The server updates ProgressTaskEventArgs.IsStopped after it receives the stop notification. In this case your code inside RunTask should exit the long running task as soon as possible;

  4. If the task is not interrupted, it can continue to run until it finishes. You can provide a client side event handler via ClientSideOnTaskDone property to be notified when the task finishes.

Below is an example of a simple long running task that does nothing but calling System.Threading.Thread.Sleep:

private void ProgressBar1_RunTask(object sender, 
    EO.Web.ProgressTaskEventArgs e)
{
    for (int i = 0; i < 100; i++)
    {
        //Check whether the task has been stopped
        if (e.IsStopped)
            break;
    
        //Perform some work
        System.Threading.Thread.Sleep(1000);
        
        //Update client side progress
        e.UpdateProgress(i, null);
    }
}

Multi-CPU/Web farm Considerations

In a multi-CPU/Web farm environment, it is possible that the "start notification" is sent to one server and the "stop notification" is sent to another server. In this case ProgressTaskEventArgs.IsStopped will not be correctly updated. In order to avoid this situation, you should call RegisterTaskNotify to register your own event handlers to handle task stop event and add additional logic into your RunTask handler accordingly to determine whether the task is stopped. For example, you can:

  • Maintain a "RunningTask" table in your database;
  • Update this table when you receive a task stop event;
  • Inside your RunTask event handler, you can query this table to determine whether the task is stopped instead of relying on ProgressTaskEventArgs.IsStopped.

Session Variable Considerations

By default, while your code is running, ASP.NET locks the session object. In this case if user tries to navigate to another page that needs to access session variables without first stopping the task, ASP.NET will not be able to process the request, because it is unable to acquire a lock on the session variable due to the lock is already being held by the page where the task is running.

To avoid this problem, considering adding EnableSessionState="false" or EnableSessionState="ReadOnly" into your @Page directive. Set it to ReadOnly if you still wish to read session variables, but do not want to change it. Set it to false if you do not need to access any session variables at all.