Message 1 of 5
Multithreading and WPF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good afternoon,
I have a modeless command set up, using the managed API to create a large number of entities (think 5000+) based on external data provided by a point-of-sales program. Currently this command uses Windows.Forms to display a modeless dialog that notifies the user about its progress (which works just fine).
I've been trying (and failing) to rewrite the interface as window under WPF.
My first attempt was as follows:
{code}
Dim Splash as New SplashDialog() 'Inherits from System.Windows.Window
Dim WPF As New Windows.Interop.WindowInteropHelper(Splash)
WPF.Owner = AcAp.Application.DocumentManager.MdiActiveDocument.Window.Handle
Splash.Show()
{code}
What I noticed was that any delegates invoked through the splash window's Dispatcher would not update the UI. I think this is because this window is on the same thread as my command. Therefore the UI won't update until my thread is complete (not what I want).
I also tried creating the window on a new thread:
{code}
Protected Shared Splash As SplashDialog() 'Inherits from System.Windows.Window
Protected Shared WithEvents Worker As New System.ComponentModel.BackgroundWorker()
Protected Shared Sub Work(ByVal Sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Worker.DoWork
Splash = New SplashDialog()
Dim WPF As New Windows.Interop.WindowInteropHelper(Splash)
WPF.Owner = AcAp.Application.DocumentManager.MdiActiveDocument.Window.Handle
Splash.Show()
System.Windows.Threading.Dispatcher.Run()
End Sub
{code}
The above approach also doesn't work. The variable holding a reference to the form is null, and I think it's because the main thread isn't waiting for the UI thread to finish initializing the new window.
Any advice?
Regards,
JB
I have a modeless command set up, using the managed API to create a large number of entities (think 5000+) based on external data provided by a point-of-sales program. Currently this command uses Windows.Forms to display a modeless dialog that notifies the user about its progress (which works just fine).
I've been trying (and failing) to rewrite the interface as window under WPF.
My first attempt was as follows:
{code}
Dim Splash as New SplashDialog() 'Inherits from System.Windows.Window
Dim WPF As New Windows.Interop.WindowInteropHelper(Splash)
WPF.Owner = AcAp.Application.DocumentManager.MdiActiveDocument.Window.Handle
Splash.Show()
{code}
What I noticed was that any delegates invoked through the splash window's Dispatcher would not update the UI. I think this is because this window is on the same thread as my command. Therefore the UI won't update until my thread is complete (not what I want).
I also tried creating the window on a new thread:
{code}
Protected Shared Splash As SplashDialog() 'Inherits from System.Windows.Window
Protected Shared WithEvents Worker As New System.ComponentModel.BackgroundWorker()
Protected Shared Sub Work(ByVal Sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Worker.DoWork
Splash = New SplashDialog()
Dim WPF As New Windows.Interop.WindowInteropHelper(Splash)
WPF.Owner = AcAp.Application.DocumentManager.MdiActiveDocument.Window.Handle
Splash.Show()
System.Windows.Threading.Dispatcher.Run()
End Sub
{code}
The above approach also doesn't work. The variable holding a reference to the form is null, and I think it's because the main thread isn't waiting for the UI thread to finish initializing the new window.
Any advice?
Regards,
JB