Bagikan melalui


ConnectivityStatus.IsOffline Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah aplikasi dalam mode 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

Nilai Properti

true jika aplikasi dalam mode offline; jika tidak, false.

Contoh

Contoh kode berikut menunjukkan cara menggunakan properti ini untuk memperbarui status offline tergantung pada nilai kotak centang. Dalam contoh ini, penanganan CheckedChanged aktivitas memperbarui status offline. Jika pengguna mengatur aplikasi ke status online, penanganan aktivitas mencoba memvalidasi ulang pengguna. Namun, jika server autentikasi tidak tersedia, penanganan aktivitas mengembalikan aplikasi ke status 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

Keterangan

Saat Anda mengatur IsOffline properti , kelas menyimpan ConnectivityStatus nilai ke sistem file lokal. Penyedia layanan klien di System.Web.ClientServices.Providers namespace layanan memeriksa nilai ini untuk menentukan apakah akan menggunakan cache data offline alih-alih mencoba mengakses autentikasi, peran, dan layanan profil Microsoft Ajax terkait.

Berlaku untuk

Lihat juga