简体   繁体   中英

asp.net PageAsyncTask not running asynchronously

I have a PageAsyncTask that takes about 2 mins to run. My page directive has Async="true", my config has the timeout as 180 (3 mins to give extra time), but when I call Page.ExecuteRegisteredAsyncTasks() it doesn't come back right away and is blocking while it's running the task.

Am I missing any steps to get this to run asynchronously?

(this was formatted better but after edit it screwed it all up)

// in my button click event
MyTask task = new MyTask();
PageAsyncTask asyncTask = new PageAsyncTask(task.OnBegin, task.OnEnd, task.OnTimeout);
Page.RegisterAsyncTask(asyncTask);
Page.ExecuteRegisteredAsyncTasks();


// MyTask.cs
public class MyTask
{
    protected delegate void AsyncTaskDelegate();
    private AsyncTaskDelegate dlgt;

    public void Run() { // my code that hits DB }

    public IAsyncResult OnBegin(object sender, EventArgs e, AsyncCallback cb, object extra)
    {
        dlgt = new AsyncTaskDelegate();
        IAsyncResult result = dlgt.BeginInvoke(extra, cb, null);
        return result;
    }
}

I misunderstood what this was about. I just went with making a new thread for the task as the main point of the task is to insert records into the DB and my page has a gridview on it reading the DB using ajax which shows the progress. So as the thread is working you can see record counts go up.

Thread myThread = new Thread(new ParameterizedThreadStart(task.Run));
myThread.Start(extra);

Thanks!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM