H H

H H

  • NA
  • 11
  • 569

updating a asp.net 4.0 webform ui controls from a Task

Dec 26 2016 7:44 AM
Hi have asp.net 4.0 webfrom with UpdatePanel and AjaxControlsToolKit.
Inside this web from I have a Task who runs on a generic list of recipients and send them the mail while also saving it as a pdf file in a files server and uploading it via web service to the organization ERP system.
I want to catch/log errors during the task process and in the end to show them to the user and let him run the process on them again.
  1. Task sendMailTask =  
  2. Task.Factory.StartNew((stateObj) =>  
  3. {  
  4. // some code with for loop on a collection of receipents who call another function which try to save the file using the web service in the ERP.  
  5. },2000);  
  6. try  
  7. {  
  8. if (!sendMailTask.IsCanceled && !sendMailTask.IsFaulted)  
  9. {  
  10. StatusMessagesContainerModalDialog.Attributes["class"] = "modal-content alert-success";  
  11. StatusMessagesContainer.CssClass = "text-center";  
  12. Status.Text = "Your email was sent";  
  13. StatusMessagesModalPopup.Show();  
  14. }  
  15. }  
  16. catch (AggregateException ex)  
  17. {  
  18. StatusMessagesContainerModalDialog.Attributes["class"] = "modal-content alert-warning";  
  19. StatusMessagesContainer.CssClass = "text-center";  
  20. Status.Text = "Error occured";  
  21. StatusMessagesModalPopup.Show();  
  22. }  
 
How can update the ui?
Right now the user get a message that the email was sent immediately before the task completed and when i try to update the ui from the task itself even when using ContinueWith nothing happens in the ui tread and the user does not see the data i want him to see.