tags:

views:

32

answers:

1

Hi,

I've implemented some WCF code that returns me the data from a WCF call, it works, but behaves syncronously.

    IAsyncResult BeginGetAsyncData(object src, EventArgs args, AsyncCallback cb, object state)
    {
        _client = new ServiceReference1.Service1Client();

        return _client.BeginGetPermissionsByStaffID("xxx", cb, state);
    }

    void EndGetAsyncData(IAsyncResult ar)
    {
        //ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        ServiceReference1.tblUser_Permission[] permissions = _client.EndGetPermissionsByStaffID(ar);

        System.Threading.Thread.Sleep(2000);

        dgResults.DataSource = permissions;
        dgResults.DataBind(); 
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        PageAsyncTask task = new PageAsyncTask(BeginGetAsyncData, EndGetAsyncData, null, null);

        Page.RegisterAsyncTask(task);

        txtOut.Text = "Waiting...";
    }

What I am seeing is a two second pause, and THEN the "waiting" message appears. I didn't explicitly spawn a new thread, but as I understand it, that's not necessary when I define the WCF service as asyncronous.

Any help would be appreciated!

+1  A: 

An PageAsyncTask executes Asynchronously against the other processes during the page lifecycle.

The actual page isn't delivered to the browser until all of those Asynchronous tasks complete...and that's when the user is going to see the change to the text of his button.

Justin Niessner
Doh! That makes sense. I guess that still has it's advantages if you have a couple of things that may take a while. Can condense the time at the server so the user sees less of a delay.Thanks!
Mark Kadlec