private void StartupContactSubscription(AsyncTask task, object state) { if (m_contactGroupServices.CurrentState != CollaborationSubscriptionState.Idle) { task.Complete(null); return; } m_contactGroupServices.NotificationReceived += this.ContactGroupServices_NotificationReceived; task.DoOneStep( delegate() { Logger.Log(Logger.LogLevel.Info, "Starting contact subscription."); m_contactGroupServices.BeginSubscribe( delegate(IAsyncResult ar) { task.DoFinalStep( delegate() { m_contactGroupServices.EndSubscribe(ar); Logger.Log(Logger.LogLevel.Info, "Started contact subscription."); }); }, null); }); }
// Callback triggered when subscription to ContactGroupServices // completes private void EndSubscribeCompleted(IAsyncResult ar) { ContactGroupServices services = ar.AsyncState as ContactGroupServices; try { services.EndSubscribe(ar); _waitForSubscribedToContactsGroupsCompleted.Set(); } catch (RealTimeException exception) { Console.WriteLine("Contact Group Subscription failed due to exception: {0}", exception.ToString()); } }
// Callback method referred to in the call to BeginSubscribe on the ContactGroupServices instance. private void ContactGroupSubscribeCB(IAsyncResult ar) { ContactGroupServices services = ar.AsyncState as ContactGroupServices; try { services.EndSubscribe(ar); Console.WriteLine("In ContactGroupSubscribeCB, state is {0}", services.CurrentState.ToString()); } // A production application should have catch blocks for a number // of other exceptions, including OperationFailureException and PublishSubscribeException. catch (RealTimeException exception) { Console.WriteLine("Contact Group Subscription failed due to exception: {0}", exception.ToString()); } }