ConnectivityStatus.IsOffline Propriété

Définition

Obtient ou définit une valeur indiquant si une application est en mode hors connexion.

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

Valeur de propriété

true si l'application est en mode hors connexion ; sinon, false.

Exemples

L’exemple de code suivant montre comment utiliser cette propriété pour mettre à jour les status hors connexion en fonction d’une valeur de zone de case activée. Dans cet exemple, un gestionnaire d’événements CheckedChanged met à jour le status hors connexion. Si l’utilisateur définit l’état en ligne de l’application, le gestionnaire d’événements tente de revalider l’utilisateur. Toutefois, si le serveur d’authentification n’est pas disponible, le gestionnaire d’événements retourne l’application à l’état hors connexion.

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

Remarques

Lorsque vous définissez la IsOffline propriété, la ConnectivityStatus classe met en cache la valeur dans le système de fichiers local. Les fournisseurs de services clients de l’espace System.Web.ClientServices.Providers de noms case activée cette valeur pour déterminer s’il faut utiliser le cache de données hors connexion au lieu de tenter d’accéder aux services d’authentification, de profil et de rôle Microsoft Ajax associés.

S’applique à

Voir aussi