Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a form contain a button . Onclick of button i will execute some functionality.
i am using repostiory pattern.
not what i want , after button click the functionility starts at background and when functionality completed then a message appears where ever i have that time

code is below
C#
public async Task<actionresult> UploadOrderTypeXls(HttpPostedFileBase orderTypeFile)
       {
           var result = string.Empty;
           if (orderTypeFile != null && orderTypeFile.ContentLength > 0)
           {
               string fileName = Common.SaveXLSFile(orderTypeFile, "OrderType");
               if (!String.IsNullOrEmpty(fileName))
               {
                   try
                   {
                      // await Task.(10000);
                        result = await methodAsync();
                      // await GetData(orderTypeFile);
                   }
                   catch (Exception ex)
                   {
                       Console.WriteLine(ex.Message);
                   }

               }
           }
           return JavaScript("ETLStatus('"+result+"')");
       }
       private Task<string> methodAsync()
       {
           return Task.Run(() =>
           {
               return _BusinesObject._masterOrderType.RunEtlJobs("MasterOrderType");
           });
       }


but problem is that this code will halt my form untill/unless execution not completed.
please help me in this
Posted
Updated 19-Jan-15 21:41pm
v2
Comments
Praveen Kumar Upadhyay 20-Jan-15 4:40am    
It is because you are calling await. So it will stop your execution and wait for the output.
sharmarun 20-Jan-15 5:05am    
yes i solute that.
now pls let me know how do i get the task status

my code is public ActionResult UploadOrderTypeXls(HttpPostedFileBase orderTypeFile)
{
var result = string.Empty;
if (orderTypeFile != null && orderTypeFile.ContentLength > 0)
{
string fileName = Common.SaveXLSFile(orderTypeFile, "OrderType");
if (!String.IsNullOrEmpty(fileName))
{
try
{
Task t = Task.Run(() =>
{
_BusinesObject._masterOrderType.RunEtlJobs("MasterOrderType");
});
TaskStatus ts = t.Status;
while (t.Status == TaskStatus.RanToCompletion)
{
return JavaScript("EnableUploadButton()");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

}
}
return JavaScript("EnableUploadButton()");
}
pr

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900