Share via


ConnectivityStatus.IsOffline Proprietà

Definizione

Ottiene o imposta un valore che indica se un'applicazione è in modalità 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

Valore della proprietà

true se l'applicazione si trova in modalità offline; in caso contrario false.

Esempio

Il codice di esempio seguente illustra come usare questa proprietà per aggiornare lo stato offline a seconda di un valore della casella di controllo. In questo esempio un CheckedChanged gestore eventi aggiorna lo stato offline. Se l'utente imposta l'applicazione sullo stato online, il gestore eventi tenta di riconvalidare l'utente. Tuttavia, se il server di autenticazione non è disponibile, il gestore eventi restituisce l'applicazione allo stato 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

Commenti

Quando si imposta la proprietà, la IsOfflineConnectivityStatus classe memorizza nella cache il valore nel file system locale. I provider di servizi client nello System.Web.ClientServices.Providers spazio dei nomi controllano questo valore per determinare se usare la cache dei dati offline anziché tentare di accedere all'autenticazione, ai ruoli e ai servizi di profilo microsoft associati.

Si applica a

Vedi anche