ConnectivityStatus.IsOffline Propiedad

Definición

Obtiene o establece un valor que indica si una aplicación está en modo sin conexión.

public:
 static property bool IsOffline { bool get(); void set(bool value); };
public static bool IsOffline { get; set; }
static member IsOffline : bool with get, set
Public Shared Property IsOffline As Boolean

Valor de propiedad

true si la aplicación está en modo sin conexión; en caso contrario, false.

Ejemplos

En el código de ejemplo siguiente se muestra cómo usar esta propiedad para actualizar el estado sin conexión en función de un valor de casilla de verificación. En este ejemplo, un CheckedChanged controlador de eventos actualiza el estado sin conexión. Si el usuario establece la aplicación en el estado en línea, el controlador de eventos intenta volver a validar el usuario. Sin embargo, si el servidor de autenticación no está disponible, el controlador de eventos devuelve la aplicación al estado sin conexión.

private void workOfflineCheckBox_CheckedChanged(
    object sender, EventArgs e)
{
    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked;
    if (!ConnectivityStatus.IsOffline)
    {
        try
        {
            // Silently re-validate the user.
            ((ClientFormsIdentity)
                System.Threading.Thread.CurrentPrincipal.Identity)
                .RevalidateUser();

            // If any settings have been changed locally, save the new
            // new values to the Web settings service.
            SaveSettings();

            // If any settings have not been changed locally, check 
            // the Web settings service for updates. 
            Properties.Settings.Default.Reload();
        }
        catch (System.Net.WebException)
        {
            MessageBox.Show(
                "Unable to access the authentication service. " +
                Environment.NewLine + "Staying in offline mode.",
                "Warning", MessageBoxButtons.OK, 
                MessageBoxIcon.Warning);
            workOfflineCheckBox.Checked = true;
        }
    }
}
Private Sub workOfflineCheckBox_CheckedChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles workOfflineCheckBox.CheckedChanged

    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked
    If Not ConnectivityStatus.IsOffline Then

        Try

            ' Silently re-validate the user.
            CType(System.Threading.Thread.CurrentPrincipal.Identity,  _
                ClientFormsIdentity).RevalidateUser()

            ' If any settings have been changed locally, save the new
            ' new values to the Web settings service.
            SaveSettings()

            ' If any settings have not been changed locally, check 
            ' the Web settings service for updates. 
            My.Settings.Reload()

        Catch ex As System.Net.WebException

            MessageBox.Show( _
                "Unable to access the authentication service. " & _
                Environment.NewLine + "Staying in offline mode.", _
                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            workOfflineCheckBox.Checked = True

        End Try

    End If
End Sub

Comentarios

Al establecer la IsOffline propiedad , la ConnectivityStatus clase almacena en caché el valor en el sistema de archivos local. Los proveedores de servicios de cliente del System.Web.ClientServices.Providers espacio de nombres comprueban este valor para determinar si se debe usar la caché de datos sin conexión en lugar de intentar acceder a los servicios de perfil, roles y autenticación de Microsoft Ajax asociados.

Se aplica a

Consulte también