2012-04-15 16 views
3

.NET 3.5アプリケーションで新しいUIスレッドを作成する次のコードがあります。WPF Dispatcher.RunがWin 7でnull例外をスローする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(); 
     }   

クラッシュはここに示されている:これは、Windowsの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スレッドで作成されていたため、アプリケーションの起動に必要なWebサービスへの認証をUIスレッドで実行できるようになりました。これは、メインのUIスレッドでWebサービスメソッドを呼び出すことは、このthread on MSDNに基づいて問題があるように見えます。

幸いなことに、これはUIサービス上でWebサービスメソッドが同期的に呼び出されるアプリケーション内の唯一の場所です。

バックグラウンドスレッド上のWebサービスに対する認証中に、メインUIスレッドの進行状況ウィンドウを起動するように変更した後、これまで問題は発生していません。 興味深いことに、Windows 7 x32を含む他のバージョンのWindowsではこの問題は発生しませんでした。

関連する問題