Aug 27, 2015, 2:19 PM
[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.
Thanks & BR,
PRASAD
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]