Windows Dev Center

WebRequestExtensions.GetCurrentNetworkInterface Method

Gets all available information about the network interface that corresponds to a web request.

Namespace:  Microsoft.Phone.Net.NetworkInformation
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)

public static NetworkInterfaceInfo GetCurrentNetworkInterface(
	this WebRequest request
)

Parameters

request
Type: System.Net.WebRequest
The web request for which to get the information.

Return Value

Type: Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceInfo
All available information about the network interface. Use the InterfaceType and InterfaceSubtype properties to determine the network interface technology.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type WebRequest. When you use instance method syntax to call this method, omit the first parameter.

This method must be invoked from the UI thread.

For more information about extension methods, see Extension Methods (C# Programming Guide) or How to: Call an Extension Method (Visual Basic).

The following example shows how to call the GetCurrentNetworkInterface method from the UI thread. The call to GetCurrentNetworkInterface throws a NetworkException if the web request has already completed.


private void response_Callback(IAsyncResult asyncResult)
        {                      
            HttpWebRequest httpWebRequest = (HttpWebRequest)asyncResult.AsyncState;
            Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    NetworkInterfaceInfo networkInterfaceInfo = httpWebRequest.GetCurrentNetworkInterface();
                    System.Diagnostics.Debug.WriteLine(networkInterfaceInfo.InterfaceType.ToString());
                }
                catch (NetworkException networkException)
                {
                    if (networkException.NetworkErrorCode == NetworkError.WebRequestAlreadyFinished)
                    {
                        System.Diagnostics.Debug.WriteLine("Cannot call GetCurrentNetworkInterface if the webrequest is already complete");
                    }
                }
            }
           );                      
            
        }       

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2015 Microsoft