Share via


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 기반 애플리케이션의 네트워크 연결을 지정 합니다. 설정한 경우 합니다 IsOffline 속성을 true, 클라이언트 서비스 공급자 해당 웹 서비스에 액세스 하는 대신 오프 라인 캐시를 사용 합니다. 오프 라인 상태는 사용자 당 및 애플리케이션 별로 저장 됩니다. 자세한 내용은 방법: 클라이언트 애플리케이션 서비스에서 오프라인으로 작업을 참조하세요.

속성

IsOffline

애플리케이션이 오프라인 모드인지 여부를 나타내는 값을 가져오거나 설정합니다.

적용 대상

추가 정보