[CLOSED] Updating progress to the user when executing Long Tasks.

  1. #1

    [CLOSED] Updating progress to the user when executing Long Tasks.

    Hi,

    I referred following link
    https://examples3.ext.net/#/MessageBox/Basic/Overview/
    (For Button5) to update the progress of long running task to user.

    This does not work in my scenario as HttpContext.Current is lost when the code enters in "LongAction" Method. HttpContext.Current is present in "StartLongAction" Method !

    By the way, I need HttpContext.Current to find the logged in user to complete the tasks in LongAction. Also, I cannot keep this in some hidden variable and use when needed as LongAction gives a call to standard library which in turn uses the HttpContext.

    I have attached the Sample code for your ready reference.


    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Threading" %>
    
    <script runat="server">
        
        
        protected void Button5_Click(object sender, DirectEventArgs e)
        {
           X.Msg.Show(new MessageBoxConfig
            {
                Title = "Please wait",
                Message = "Loading items...",
                ProgressText = "Initializing...",
                Width = 300,
                Progress = true,
                Closable = false,
                AnimEl = this.Button5.ClientID
            });
            
            this.StartLongAction();
        }
    
      
        
        private void StartLongAction()
        {
            this.Session["Task1"] = 100;
            ThreadPool.QueueUserWorkItem(LongAction);
            
            this.TaskManager1.StartTask("Task1");
        }
    
        private void LongAction(object state)
        {
            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(1000);
                this.Session["Task1"] = i + 1;
            }
            this.Session.Remove("Task1");
        }
    
        protected void RefreshProgress(object sender, DirectEventArgs e)
        {
            object progress = this.Session["Task1"];
            if (progress != null)
            {
               X.Msg.UpdateProgress(((int)progress) / 10f, string.Format("Step {0} of {1}...", progress.ToString(), 10));
            }
            else
            {
                this.TaskManager1.StopTask("Task1");
                X.MessageBox.Hide();
                this.ResourceManager1.AddScript("Ext.Msg.notify('Done', 'Your items were loaded!');");
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>MessageBox - Ext.NET Examples</title>   
        
      
        <script>
            var showResult = function (btn) {
                Ext.Msg.notify("Button Click", "You clicked the " + btn + " button");
            };
    
            var showResultText = function (btn, text) {
                Ext.Msg.notify("Button Click", "You clicked the " + btn + 'button and entered the text "' + text + '".');
            };
        </script> 
        
        <style>
            .x-window-dlg .ext-mb-download {
                background : transparent url(resources/images/download.gif) no-repeat top left;
                height : 46px;
            }
        </style>  
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <h1>MessageBox Dialogs</h1>
        
        <p>The following samples demonstrate how to display various MessageBox options.</p>
        
        
        
        <h2>5. Progress Dialog</h2>
        
        <span>Dialog with measured progress bar.</span>
        
        <ext:Button ID="Button5" runat="server" Text="Show" OnDirectClick="Button5_Click" />
    
        <ext:TaskManager ID="TaskManager1" runat="server">
            <Tasks>
                <ext:Task 
                    TaskID="Task1"
                    Interval="1000" 
                    AutoRun="false">
                    <DirectEvents>
                        <Update OnEvent="RefreshProgress" />
                    </DirectEvents>                    
                </ext:Task>
            </Tasks>
        </ext:TaskManager>
    
       
    </body>
    </html>
    Please guide Or Is there any other way to indicate user in case of long running tasks.

    Thanks & BR,
    PRASAD
    Last edited by Daniil; Aug 28, 2015 at 8:46 AM. Reason: [CLOSED]
  2. #2
    Hi @Arohan,

    While LongAction is being executed, it is not a page request anymore. It is just a thread on server. More details with suggestions what to do you can find in this StackOverflow discussion.
    http://stackoverflow.com/questions/5...t-returns-null
  3. #3
    Hi,

    Thanks. Understood the point. I should not use the object which refers ASP.Net object like HttpContext.

    You may close this thread.

    Thanks & BR,
    PRASAD
    Last edited by Arohan; Aug 28, 2015 at 7:39 AM.

Similar Threads

  1. [CLOSED] Status Code: Status Text: BADRESPONSE: Unexpected token <
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 10, 2014, 7:02 PM
  2. Replies: 1
    Last Post: Nov 28, 2013, 6:34 AM
  3. Replies: 5
    Last Post: May 27, 2013, 5:30 AM
  4. Replies: 16
    Last Post: Oct 04, 2011, 5:17 PM
  5. status text status code CUSTOM
    By threewonders in forum 1.x Help
    Replies: 0
    Last Post: Sep 26, 2011, 1:29 PM

Tags for this Thread

Posting Permissions