My code:
protected void Page_Load(object sender, EventArgs e)
{
PageAsyncTask t = new PageAsyncTask(cancelPayPalAsync());
Page.RegisterAsyncTask(t);
// Execute the register asynchronous task.
Page.ExecuteRegisteredAsyncTasks();
}
Which calls:
public async Task cancelPayPalAsync()
{
//Leaving blank for security reasons
}
This line here: PageAsyncTask t = new PageAsyncTask(cancelPayPalAsync());
more specifically cancelPayPalAsync
is spitting out the error
Cannot convert System.Threading.Task.Tasks to System.Func<System.Func<System.Threading.Tasks.Task>
I'm aiming to make the page wait for my code to execute before loading, using my Async method. I don't know how to deal with this problem, and I don't see any solutions on the internet/stackoverflow.
Thanks!
As Guru Stron pointed out in a comment, adding the () to PageAsyncTask t = new PageAsyncTask(cancelPayPalAsync());
makes it refer to a function that returns a task rather than the task itself.
PageAsyncTask t = new PageAsyncTask(cancelPayPalAsync);
will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.