Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Loading wpf windows forms in advance on Application startup

$
0
0

Hi

I have a number of XAML Windows which user can navigate to when main window is loaded in the above Menu control.  If user clicks 'WindowB' in the MenuItem, then I create a new WindowB and assign it to Application.MainWindow property.

However, this takes time to load initially and freezes the UI so I wanted to load the WindowB, WindowC in advance on a separate thread of the UI thread so that when user clicks, it would take less time to do initial loading.  Code below was used

 Public Class App_Class
        Inherits System.Windows.Application

        Private Sub App_Startup(ByVal sender As Object, ByVal e As StartupEventArgs)


            Me.StartupUri = New System.Uri("RegisterWindow.xaml", System.UriKind.Relative)

            Dim A As System.Threading.Thread = New System.Threading.Thread(AddressOf formsLoad)
            A.SetApartmentState(System.Threading.ApartmentState.STA)
            A.Priority = System.Threading.ThreadPriority.Lowest
            A.Start()

        End Sub

        Private Sub formsLoad()

            Dim saleWindow As New SaleWindow
            Dim deleteWindow As New DeleteInvoiceWindow

        End Sub

Error is:

{"An entry with the same key already exists."}

in my NavigationControl.xaml that WindowA, WindowB each instantiates in XAML for the Menu above.  Any advice?  Thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>