InternalGetIsNetworkAvailable() 정적인 개인적인 메소드

static private InternalGetIsNetworkAvailable ( ) : bool
리턴 bool
예제 #1
0
            private static void ChangedAddress(object sender, EventArgs eventArgs)
            {
                lock (syncObject){
                    bool isAvailableNow = SystemNetworkInterface.InternalGetIsNetworkAvailable();

                    if (isAvailableNow != isAvailable)
                    {
                        isAvailable = isAvailableNow;

                        DictionaryEntry[] callerArray = new DictionaryEntry[s_availabilityCallerArray.Count];
                        s_availabilityCallerArray.CopyTo(callerArray, 0);

                        for (int i = 0; i < callerArray.Length; i++)
                        {
                            NetworkAvailabilityChangedEventHandler handler = (NetworkAvailabilityChangedEventHandler)callerArray[i].Key;
                            ExecutionContext context = (ExecutionContext)callerArray[i].Value;
                            if (context == null)
                            {
                                handler(null, new NetworkAvailabilityEventArgs(isAvailable));
                            }
                            else
                            {
                                ExecutionContext.Run(context.CreateCopy(), s_RunHandlerCallback, handler);
                            }
                        }
                    }
                }
            }
            private static void ChangedAddress(object sender, EventArgs eventArgs)
            {
                lock (s_syncObject)
                {
                    bool isAvailableNow = SystemNetworkInterface.InternalGetIsNetworkAvailable();

                    if (isAvailableNow != s_isAvailable)
                    {
                        s_isAvailable = isAvailableNow;

                        var s_copy =
                            new Dictionary <NetworkAvailabilityChangedEventHandler, ExecutionContext>(s_availabilityCallerArray);

                        foreach (var handler in s_copy.Keys)
                        {
                            ExecutionContext context = s_copy[handler];
                            if (context == null)
                            {
                                handler(null, new NetworkAvailabilityEventArgs(s_isAvailable));
                            }
                            else
                            {
                                ExecutionContext.Run(context, s_RunHandlerCallback, handler);
                            }
                        }
                    }
                }
            }
예제 #3
0
        public static bool GetIsNetworkAvailable()
        {
#if WASM
            throw new PlatformNotSupportedException();
#else
            return(SystemNetworkInterface.InternalGetIsNetworkAvailable());
#endif
        }
            private static void ChangedAddress(object?sender, EventArgs eventArgs)
            {
                Dictionary <NetworkAvailabilityChangedEventHandler, ExecutionContext?>?availabilityChangedSubscribers = null;

                lock (s_globalLock)
                {
                    bool isAvailableNow = SystemNetworkInterface.InternalGetIsNetworkAvailable();

                    // If there is an Availability Change, need to execute user callbacks.
                    if (isAvailableNow != s_isAvailable)
                    {
                        s_isAvailable = isAvailableNow;

                        if (s_availabilityChangedSubscribers.Count > 0)
                        {
                            availabilityChangedSubscribers = new Dictionary <NetworkAvailabilityChangedEventHandler, ExecutionContext?>(s_availabilityChangedSubscribers);
                        }
                    }
                }

                // Executing user callbacks if Availability Change event occured.
                if (availabilityChangedSubscribers != null)
                {
                    bool isAvailable = s_isAvailable;
                    NetworkAvailabilityEventArgs args = isAvailable ? s_availableEventArgs : s_notAvailableEventArgs;
                    ContextCallback callbackContext   = isAvailable ? s_runHandlerAvailable : s_runHandlerNotAvailable;

                    foreach (KeyValuePair <NetworkAvailabilityChangedEventHandler, ExecutionContext?>
                             subscriber in availabilityChangedSubscribers)
                    {
                        NetworkAvailabilityChangedEventHandler handler = subscriber.Key;
                        ExecutionContext?ec = subscriber.Value;

                        if (ec == null) // Flow supressed
                        {
                            handler(null, args);
                        }
                        else
                        {
                            ExecutionContext.Run(ec, callbackContext, handler);
                        }
                    }
                }
            }
            private static void ChangedAddress(object sender, EventArgs eventArgs)
            {
                DictionaryEntry[] callerArray = null;

                lock (s_globalLock) {
                    bool isAvailableNow = SystemNetworkInterface.InternalGetIsNetworkAvailable();

                    if (isAvailableNow != isAvailable)
                    {
                        isAvailable = isAvailableNow;

                        callerArray = new DictionaryEntry[s_availabilityCallerArray.Count];
                        s_availabilityCallerArray.CopyTo(callerArray, 0);
                    }
                }

                // Release the s_globalLock before calling into user callback.
                if (callerArray != null)
                {
                    // Synchronization dedicated just to the invocation of the callback,
                    // for back compat reason.
                    lock (s_protectCallbackLock)
                    {
                        Debug.Assert(!Monitor.IsEntered(s_globalLock), "Should not invoke user callback while holding globalLock");

                        foreach (var entry in callerArray)
                        {
                            NetworkAvailabilityChangedEventHandler handler = (NetworkAvailabilityChangedEventHandler)entry.Key;
                            ExecutionContext context = (ExecutionContext)entry.Value;
                            if (context == null)
                            {
                                handler(null, new NetworkAvailabilityEventArgs(isAvailable));
                            }
                            else
                            {
                                ExecutionContext.Run(context.CreateCopy(), s_RunHandlerCallback, handler);
                            }
                        }
                    }
                }
            }
            private static void ChangedAddress(object sender, EventArgs eventArgs)
            {
                Dictionary <NetworkAvailabilityChangedEventHandler, ExecutionContext> copy = null;

                lock (s_globalLock)
                {
                    bool isAvailableNow = SystemNetworkInterface.InternalGetIsNetworkAvailable();

                    // If there is an Availability Change, need to execute user callbacks.
                    if (isAvailableNow != s_isAvailable)
                    {
                        s_isAvailable = isAvailableNow;

                        copy =
                            new Dictionary <NetworkAvailabilityChangedEventHandler, ExecutionContext>(s_availabilityCallerArray);
                    }
                }

                // Executing user callbacks if Availability Change event occured.
                if (copy != null)
                {
                    foreach (var entry in copy)
                    {
                        NetworkAvailabilityChangedEventHandler handler = entry.Key;
                        ExecutionContext context = entry.Value;
                        if (context == null)
                        {
                            handler(null, new NetworkAvailabilityEventArgs(s_isAvailable));
                        }
                        else
                        {
                            ExecutionContext.Run(context, s_RunHandlerCallback, handler);
                        }
                    }
                }
            }
예제 #7
0
 public static bool GetIsNetworkAvailable()
 {
     return(SystemNetworkInterface.InternalGetIsNetworkAvailable());
 }