I am using ASP.Net and what i want to achieve is that i have a service that i call, before calling the service i manipulate some UI controls and after the service is completed i manipulate the UI controls again.
Problem is that the UI controls values are never changed in the body of the Task.Factory (After service call is completed) and no exceptions fired.
Here is my code:
try
{
Task ocrTask = Task.Factory.StartNew(() =>
{
OCRResult result = new OCRServiceHandler().Start(image);
if (string.IsNullOrEmpty(result.Error))
{
ViewState["OCRResult"] = result;
lbl_Status.Text = string.Empty;
div_Result.Visible = true;
}
else
{
ViewState["OCRResult"] = null;
lbl_Status.Text = result.Error;
div_Result.Visible = false;
}
//Clear upload file
myFile.Attributes.Clear();
//Hide processing image
img_Processing.Visible = false;
}, CancellationTask.None, TaskCreationOptions.None, uiScheduler);
}
catch (Exception ex)
{
throw ex;
}
I have tried using ContinueWith and update the UI controls there but same results, i have tried using ThreadStart also but same result, i have also tried changing the TaskScheduler type the same happens.