c# - wpf splash screen lagging while loading main window -


i doing wpf application , today faced troubles. need show splash screen while initializing mainwindow. code below:

public mainwindowview() {     onload(); }  public void onload() {     worker = new backgroundworker();     lw = new waitwindowview();     lw.show();     worker.dowork += delegate(object s, doworkeventargs args)     {         dispatcher.invoke(new action(delegate()         {             initializecomponent();             datacontext = new navbarvm();         }), dispatcherpriority.background);     };     worker.runworkercompleted += delegate(object s, runworkercompletedeventargs args)     {         lw.close();     };     worker.runworkerasync(); } 

above code working. splash screes lagging.

your call dispatcher.invoke make code in dowork handler run on ui thread, using backgroundthread pointless. furthermore, can't call initializecomponent on background thread either, not speed things up.

the normal way display splash screen can found in answer how open child window splash screen before mainwindow in wpf? question, here on stack overflow. if have lot of initialisation code (you, not framework), can in splash screen window , pass loaded objects mainwindow before closing splash screen.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -