ConnectivityStatus クラス

定義

アプリケーションのネットワーク接続のステータスを表します。

public ref class ConnectivityStatus abstract sealed
public static class ConnectivityStatus
type ConnectivityStatus = class
Public Class ConnectivityStatus
継承
ConnectivityStatus

次のコード例は、このクラスを使用して、チェック ボックスの値に応じてオフライン状態を更新する方法を示しています。 この例では、イベント ハンドラーによって 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

注釈

クラスを ConnectivityStatus 使用して、クライアント アプリケーション サービスを使用する Windows ベースのアプリケーションのネットワーク接続を指定します。 プロパティを IsOfflinetrue設定すると、クライアント サービス プロバイダーは、対応する Web サービスにアクセスする代わりにオフライン キャッシュを使用します。 オフライン状態は、ユーザーごとおよびアプリケーションごとに格納されます。 詳細については、「How to: Work Offline with Client Application Services」(方法: クライアント アプリケーション サービスをオフライン モードで操作する) を参照してください。

プロパティ

IsOffline

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

適用対象

こちらもご覧ください