2012-04-15 2 views
3

.NET 3.5 응용 프로그램에서 새 UI 스레드를 만들려면 다음 코드를 사용하십시오.WPF Dispatcher.Run이 Win 7에서 null 예외를 throw합니다. 64

private void OnCreateNewWindow(object sender, RoutedEventArgs e) 
     { 
      var rect = this.RestoreBounds; 
      double l = rect.Left; 
      double wth = rect.Width; 
      double t = rect.Top; 
      double ht = rect.Height; 
      var progressThread = new Thread(() => 
      { 

       progressWindow = new ProgressWindow(Visibility.Collapsed) { Height = 50, Width = 50 }; 
       progressWindow.WindowStartupLocation = WindowStartupLocation.Manual; 
       progressWindow.Left = l + (wth - progressWindow.Width)/2; 
       progressWindow.Top = t - 35 + (ht - progressWindow.Height)/2; 

       progressWindow.Show(); 
       progressWindow.Activate(); 
       Dispatcher.Run(); 
      }); 

      progressThread.SetApartmentState(ApartmentState.STA); 
      progressThread.Start(); 
     }   

충돌은 여기에 설명된다 : 이것은 윈도우 32 비트 버전에서 완벽하게 작동 enter image description here

. 64 비트 Windows 7에서 PC를 재부팅 할 때이 프로그램을 처음 실행할 때 Visual Studio 나 Visual Studio 외부에서 응용 프로그램 충돌을 통해 실행되는 경우 null 예외가 발생합니다.

예외 정보가 건조 :

[Managed to Native Transition] 
    WindowsBase.dll!MS.Win32.HwndWrapper.DestroyWindow(object args) + 0xfc bytes  
    WindowsBase.dll!MS.Win32.HwndWrapper.Dispose(bool disposing, bool isHwndBeingDestroyed) + 0xce bytes  
    WindowsBase.dll!MS.Win32.HwndWrapper.Dispose() + 0x15 bytes 
    PresentationCore.dll!System.Windows.Media.MediaContextNotificationWindow.DisposeNotificationWindow() + 0x22 bytes 
    PresentationCore.dll!System.Windows.Media.MediaContext.Dispose() + 0xba bytes 
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(object state) + 0x47 bytes  
    mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x178 bytes  
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x62 bytes  
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ShutdownImpl() + 0x87 bytes 
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x121 bytes 
> EMS.Controls.Dictionary.dll!EMS.Controls.Dictionary.Views.AuthenticateWindow.OnCreateNewWindow.AnonymousMethod() Line 56 + 0x5 bytes C# 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x9b bytes  
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x4d bytes 

내가 다시 프로그램을 계속 실행하면, 나는 것을 나타내는, 프로그램 호환성 Assitant에서 메시지를받을 :

System.NullReferenceException was unhandled 

스택 추적이 아래에 주어진다 일부 호환성 설정이 적용되었습니다. 다음에 프로그램을 실행하면 더 이상이 예외가 발생하지 않습니다. 누구든지이 경험이 있습니까?

+0

스택 추적을 게시 할 수 있습니까? –

+0

스택 추적이있는 수정 된 소식입니다. 그것은 매우 건조하다. 감사. –

+0

[외부 코드]를 마우스 오른쪽 버튼으로 클릭하고 "외부 코드 표시"를 선택하십시오 –

답변

1

이 문제는 응용 프로그램 시작 시퀀스와 관련이 있습니다. 진행 창은 별도의 UI 스레드에서 만들어 지므로 응용 프로그램 시작에 필요한 웹 서비스에 대한 인증을 UI 스레드에서 수행 할 수 있습니다. 기본 UI 스레드에서 webservice 메서드를 호출하는 것이이 thread on MSDN을 기반으로 문제가있는 것처럼 보입니다.

다행히 UI 서비스 스레드에서 웹 서비스 메서드가 동 기적으로 호출되는 응용 프로그램의 유일한 곳입니다.

배경 스레드의 웹 서비스에 인증하는 동안 기본 UI 스레드에서 진행 창을 시작하도록 변경 한 후 문제가 발생하지 않았습니다. Windows 7 x32를 비롯한 다른 Windows 버전에서도이 문제가 발생하지 않았다는 점에 흥미 롭습니다.

관련 문제