Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
- <ContentTemplate>
- <asp:Timer ID="Timer1" runat="server" Interval="500" OnTick="Timer1_Tick"></asp:Timer>
- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
- </ContentTemplate>
- <Triggers>
- <asp:AsyncPostBackTrigger ControlID="Button1" />
- <asp:AsyncPostBackTrigger ControlID="Timer1" />
- </Triggers>
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Push Me"/>
- public static int testing;
- protected void Button1_Click(object sender, EventArgs e) {
- //Initialise static
- testing = 0;
- var progress = new Progress<int>(ProgressReport);
- Task t = new Task(() => Test(progress));
- t.Start();
- }
- public void ProgressReport(int progress)
- {
- //Update the static with the current progress value
- testing = progress;
- }
- public void Test(IProgress<int> progress)
- {
- for (int i = 0; i < 10; i++)
- {
- //Pretend to do something intensive
- Thread.Sleep(1000);
- //Output the progress
- progress.Report(i);
- }
- }
- protected void Timer1_Tick(object sender, EventArgs e)
- {
- //Output the value of the static to the label
- Label1.Text = testing.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement