Friday, May 8, 2009

Asynchronous WCF Methods in Silverlight

I'm not sure whether I should love or hate a language that lets me write code like this:

   private void InitData()
    {
        RoomServiceClient rc = new RoomServiceClient(wsBinding, roomServiceEndpoint);
        rc.GetUserCompleted +=
            delegate(object sender, GetUserCompletedEventArgs e)
            {
                user = e.Result;
                rc.JoinRoomAsync(App.OwnerUserID, App.RoomName, App.UserID);
            };
        rc.JoinRoomCompleted +=
            delegate(object sender, AsyncCompletedEventArgs e)
            {
                rc.GetRoomAsync(App.OwnerUserID, App.RoomName);
            };
        rc.GetRoomCompleted += 
            delegate(object sender, GetRoomCompletedEventArgs e)
            {
                UpdateLocalState(e.Result);
            };
        rc.GetUserAsync(App.UserID);
    }

No comments :