Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
  2. <ContentTemplate>
  3. <asp:Timer ID="Timer1" runat="server" Interval="500" OnTick="Timer1_Tick"></asp:Timer>
  4. <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  5. </ContentTemplate>
  6. <Triggers>
  7. <asp:AsyncPostBackTrigger ControlID="Button1" />
  8. <asp:AsyncPostBackTrigger ControlID="Timer1" />
  9. </Triggers>
  10.  
  11. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Push Me"/>
  12.  
  13. public static int testing;
  14.  
  15. protected void Button1_Click(object sender, EventArgs e) {
  16. //Initialise static
  17. testing = 0;
  18.  
  19. var progress = new Progress<int>(ProgressReport);
  20. Task t = new Task(() => Test(progress));
  21. t.Start();
  22. }
  23.  
  24. public void ProgressReport(int progress)
  25. {
  26. //Update the static with the current progress value
  27. testing = progress;
  28. }
  29.  
  30. public void Test(IProgress<int> progress)
  31. {
  32. for (int i = 0; i < 10; i++)
  33. {
  34. //Pretend to do something intensive
  35. Thread.Sleep(1000);
  36. //Output the progress
  37. progress.Report(i);
  38. }
  39. }
  40.  
  41. protected void Timer1_Tick(object sender, EventArgs e)
  42. {
  43. //Output the value of the static to the label
  44. Label1.Text = testing.ToString();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement