protected virtual void OnAuthenticate(EventArgs e) { AuthenticationEventHandler authHandler = Authenticated; if (authHandler != null) { foreach (AuthenticationEventHandler handler in authHandler.GetInvocationList()) { handler.BeginInvoke(this, e, new AsyncCallback(Callback), handler); } } }
void Callback(IAsyncResult ar) { AuthenticationEventHandler d = (AuthenticationEventHandler)ar.AsyncState; if (d.EndInvoke(ar)) { OnLoggedIn(new EventArgs()); } else { OnLoggedError(new EventArgs()); } }
void OnAuthenticationChanged(bool state) { // make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised AuthenticationEventHandler handler = null; lock (this) { handler = m_AuthenticationChanged; } // raise event if (handler != null) { handler(state); } if (state == true) { CheckCloudDateTime(); } }