コード例 #1
0
        private void RegisterCallback(IntPtr handle, Action <RasConnectionEventArgs> callback, RASCN changeNotification)
        {
            var stateObject = new RasConnectionNotificationStateObject();
            IRegisteredCallback registeredCallback = null;

            try
            {
                registeredCallback = callbackFactory.Create(callbackHandler.OnCallback, stateObject);
                if (registeredCallback == null)
                {
                    throw new InvalidOperationException("The factory did not register a callback.");
                }

                var ret = rasApi32.RasConnectionNotification(handle, registeredCallback.Handle, changeNotification);
                if (ret != SUCCESS)
                {
                    throw exceptionPolicy.Create(ret);
                }

                stateObject.RegisteredCallback = registeredCallback;
                stateObject.Callback           = callback;
                stateObject.NotificationType   = changeNotification;

                notifications.Add(changeNotification, stateObject);
            }
            catch (Exception)
            {
                registeredCallback?.Dispose();
                throw;
            }
        }
コード例 #2
0
        private void OnCallback(RasConnectionNotificationStateObject state)
        {
            lock (syncRoot)
            {
                var current = enumConnectionsService.EnumerateConnections().ToArray();

                var changes = FindConnectionChanges(current);
                if (changes.Any())
                {
                    ExecuteCallbackForChanges(state.Callback, changes);
                }

                previousState = current;
            }
        }