ConnectivityStatus.IsOffline Propriedade

Definição

Obtém ou define um valor que indica se um aplicativo está em modo offline.

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 da propriedade

true se o aplicativo estiver no modo offline; caso contrário, false.

Exemplos

O código de exemplo a seguir demonstra como usar essa propriedade para atualizar o status offline, dependendo de um valor de caixa marcar. Neste exemplo, um CheckedChanged manipulador de eventos atualiza o status offline. Se o usuário definir o aplicativo como o estado online, o manipulador de eventos tentará revalidar novamente o usuário. No entanto, se o servidor de autenticação não estiver disponível, o manipulador de eventos retornará o aplicativo para o estado offline.

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

Comentários

Quando você define a IsOffline propriedade, a ConnectivityStatus classe armazena o valor em cache no sistema de arquivos local. Os provedores de serviços cliente no System.Web.ClientServices.Providers namespace marcar esse valor para determinar se devem usar o cache de dados offline em vez de tentar acessar a autenticação, as funções e os serviços de perfil associados do Microsoft Ajax.

Aplica-se a

Confira também