WPF Dispatcher.Run throws null exception in Win 7 64

I have the following code to create a new user interface thread in a .NET 3.5 application.

  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();
        }         

Crash shown here: enter image description here

This works great on 32-bit versions of Windows. The first time I run this program when I restart the PC on 64-bit Windows 7, I get a null exception if running through Visual Studio or the application crashes outside of Visual Studio.

Exceptions dry details:

System.NullReferenceException was unhandled

The stack trace is shown below:

    [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   

If I run the program again, I get a message from the program compatibility assistant, indicating that some compatibility settings have been applied. The next time I run the program, I no longer get this exception. Has anyone experienced this?

+3
source
1

. , -, , . , webservice MSDN.

, , webservice .

- . , Windows, Windows 7 x32.

+1

All Articles