Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register new pageasynctask with async Task method that takes parameters

I have this method in an asp.net webforms project:

private async Task SomeMethod(int accID){ // }

I want to do this in the page_load, but I'm not sure how to handle the parameters.

protected void Page_Load(object sender, EventArgs e)
    {
        RegisterAsyncTask(new PageAsyncTask(SomeMethod(int accID)));

       // etc
}
like image 746
A J Avatar asked Mar 26 '14 08:03

A J


2 Answers

Try this:

protected void Page_Load(object sender, EventArgs e)
    {
        RegisterAsyncTask(new PageAsyncTask(() => SomeMethod(accID: 1000)));

       // etc
}
like image 154
noseratio Avatar answered Sep 19 '22 00:09

noseratio


First, I know am too late to answer this, but this may still help others struggling like me.

So, you could make all the parameters of the async method optional like below:

private async Task SomeMethod(int accID=0){ // }

and then register the task in the page load event like below:

RegisterAsyncTask(new PageAsyncTask(() => SomeMethod()));

This works fine for me.

like image 31
Abhishek Tewari Avatar answered Sep 22 '22 00:09

Abhishek Tewari