관리 코드를 사용하여 Configuration Manager 비동기 오류를 처리하는 방법

비동기 쿼리 중에 발생하는 Configuration Manager 오류를 처리하려면 SmsBackgroundWorker.QueryProcessorCompleted 이벤트 처리기에 전달되는 매개 변수 Error Exception 속성을 테스트 RunWorkerCompletedEventArgs 합니다. Error가 이 아닌 null경우 예외가 발생했으며 Error를 사용하여 원인을 검색합니다.

ErrorSmsQueryException인 경우 이를 사용하여 기본 __ExtendedException 또는 SMS_ExtendedException로 가져올 수 있습니다. 관리되는 SMS 공급자 라이브러리는 이러한 예외를 래핑하지 않으므로 System.Management 네임스페이스 ManagementException 개체를 사용하여 액세스해야 합니다.

비동기 쿼리 오류를 처리하려면

  1. 비동기 쿼리를 만듭니다.

  2. 비동기 쿼리 SmsBackgroundWorker.QueryProcessorCompleted 이벤트 처리기에서 다음 예제의 코드를 구현합니다.

  3. 비동기 쿼리를 실행합니다. 예외 처리기를 테스트하려면 과 같은 Select & from &&& 잘못된 형식의 쿼리 문자열을 QueryProcessorBase.ProcessQuery 메서드에 전달합니다.

예시

다음 예제에서는 SmsBackgroundWorker.QueryProcessorCompleted 이벤트 처리기를 구현합니다.

샘플 코드 호출에 대한 자세한 내용은 코드 조각 Configuration Manager 호출을 참조하세요.

void bw1_QueryProcessorCompleted(object sender, RunWorkerCompletedEventArgs e)  
{  
    if (e.Error != null)  
    {  
        Console.WriteLine("There was an Error");  
        if (e.Error is SmsQueryException)  
        {  
            SmsQueryException queryException = (SmsQueryException)e.Error;  
            Console.WriteLine(queryException.Message);  

            // Get either the __ExtendedStatus or SMS_ExtendedStatus object and display various properties.  
            ManagementException mgmtExcept = queryException.InnerException as ManagementException;  

            if (mgmtExcept != null)  
            {  
                if (string.Equals(mgmtExcept.ErrorInformation.ClassPath.ToString(), "SMS_ExtendedStatus", StringComparison.OrdinalIgnoreCase) == true)  
                {  
                    Console.WriteLine("Configuration Manager provider exception");  
                }  

                else if (string.Equals(mgmtExcept.ErrorInformation.ClassPath.ToString(), "__ExtendedStatus", StringComparison.OrdinalIgnoreCase) == true)  
                {  
                    Console.WriteLine("WMI exception");  
                }  
                Console.WriteLine(mgmtExcept.ErrorCode.ToString());  
                Console.WriteLine(mgmtExcept.ErrorInformation["ParameterInfo"].ToString());  
                Console.WriteLine(mgmtExcept.ErrorInformation["Operation"].ToString());  
                Console.WriteLine(mgmtExcept.ErrorInformation["ProviderName"].ToString());  
            }  

        }  
        if (e.Error is SmsConnectionException)  
        {  
            Console.WriteLine("There was a connection error :" + ((SmsConnectionException)e.Error).Message);  
            Console.WriteLine(((SmsConnectionException)e.Error).ErrorCode);  
        }  
    }  

    Console.WriteLine("Done...");  
}  

예제 메서드에는 다음 매개 변수가 있습니다.

매개 변수 형식 설명
sender - Object 이벤트 원본입니다.
e - RunWorkerCompletedEventArgs 이벤트 데이터입니다.

자세한 내용은 RunWorkerCompletedEventArgs 클래스를 참조하세요.

코드 컴파일

이 C# 예제에는 다음이 필요합니다.

네임 스페이스

시스템

System.Collections.Generic

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

System.Management

System.ComponentModel

어셈블리

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

System.Management

강력한 프로그래밍

오류 처리에 대한 자세한 내용은 Configuration Manager 오류 정보를 참조하세요.

참고 항목

오류 정보