Simran Rani

Simran Rani

  • NA
  • 19
  • 315

I am trying to show the count in a label based on the time

Apr 2 2019 1:54 AM
I am trying to show the count in a label based on the time using timespan
but label always null
 
while i am debugging the code there are showing the count value in the label but not on the browser
  1. public partial class _Default : System.Web.UI.Page  
  2. {  
  3. public int j;  
  4. public int numoffers = 6000;  
  5. public int i;  
  6. protected void Page_Load(object sender, EventArgs e)  
  7. {  
  8. SetInterval(() => calculate(), TimeSpan.FromSeconds(10));  
  9. }  
  10. public void calculate()  
  11. {  
  12. DateTime time = DateTime.Now;  
  13. int hour = time.Hour;  
  14. int minute = time.Minute;  
  15. int second = time.Second;  
  16. int numofdays = 90;  
  17. int num = Check_Prime(minute);  
  18. int numofperday = numoffers / numofdays;  
  19. if (minute % 2 == 0)  
  20. {  
  21. j = j + 2;  
  22. i = numoffers - j;  
  23. }  
  24. else  
  25. {  
  26. if (num == 1)  
  27. {  
  28. j = j + 3;  
  29. i = numoffers - j;  
  30. }  
  31. else  
  32. {  
  33. j = j + 5;  
  34. i = numoffers - j;  
  35. }  
  36. }  
  37. if (j >=6000)  
  38. {  
  39. Thread.Sleep(TimeSpan.FromSeconds(100000));  
  40. }  
  41. Label2.Text = i.ToString();  
  42. }  
  43. public async Task SetInterval(Action action, TimeSpan timeout)  
  44. {  
  45. await Task.Delay(timeout).ConfigureAwait(false);  
  46. action();  
  47. SetInterval(action, timeout);  
  48. }  
  49. private int Check_Prime(int number)  
  50. {  
  51. int i;  
  52. for (i = 2; i <= number - 1; i++)  
  53. {  
  54. if (number % i == 0)  
  55. {  
  56. return 0;  
  57. }  
  58. }  
  59. if (i == number)  
  60. {  
  61. return 1;  
  62. }  
  63. return 0;  
  64. }  
  65. } 

Answers (1)