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
}
Try this:
protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(() => SomeMethod(accID: 1000)));
// etc
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With