ConnectivityStatus.IsOffline プロパティ

定義

アプリケーションがオフライン モードかどうかを示す値を取得または設定します。

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

プロパティ値

アプリケーションがオフライン モードである場合は true。それ以外の場合は false

次のコード例では、このプロパティを使用して、チェック ボックスの値に応じてオフライン状態を更新する方法を示します。 この例では、イベント ハンドラーによって CheckedChanged オフライン状態が更新されます。 ユーザーがアプリケーションをオンライン状態に設定すると、イベント ハンドラーはユーザーの再検証を試みます。 ただし、認証サーバーが使用できない場合、イベント ハンドラーはアプリケーションをオフライン状態に戻します。

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

注釈

プロパティを IsOffline 設定すると、クラスは ConnectivityStatus 値をローカル ファイル システムにキャッシュします。 名前空間のSystem.Web.ClientServices.Providersクライアント サービス プロバイダーは、関連付けられている Microsoft Ajax 認証、ロール、プロファイル サービスにアクセスするのではなく、オフライン データ キャッシュを使用するかどうかを決定するために、この値をチェックします。

適用対象

こちらもご覧ください