Share via


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 인증, 역할 및 프로필 서비스에 액세스하는 대신 오프라인 데이터 캐시를 사용할지 여부를 결정하기 위해 이 값을 검사.

적용 대상

추가 정보