ConnectivityStatus Classe

Definição

Representa o status da conexão de rede de um aplicativo.

public ref class ConnectivityStatus abstract sealed
public static class ConnectivityStatus
type ConnectivityStatus = class
Public Class ConnectivityStatus
Herança
ConnectivityStatus

Exemplos

O código de exemplo a seguir demonstra como usar essa classe 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 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

Use a ConnectivityStatus classe para especificar a conectividade de rede de aplicativos baseados no Windows que usam serviços de aplicativos cliente. Quando você define a IsOffline propriedade como true, os provedores de serviços cliente usam o cache offline em vez de tentar acessar os serviços Web correspondentes. O status offline é armazenado por usuário e por aplicativo. Para obter mais informações, consulte Como trabalhar offline com serviços de aplicativo cliente.

Propriedades

IsOffline

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

Aplica-se a

Confira também