Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!

Im quite new in wpf and need some advices to solve following problem.

In my wpf application I have multiple dialogs (windows). Every dialog has window_loaded event where I fetch some data from database and/or make some calculations.

Basic idea is this

private void Window_Loaded(object sender, RoutedEventArgs e)
{
GetDataFromDatabase();
MakeCalculations();                                   
}


Following code works well but when window is loaded there will be some laggy moments and window is unresponsive on slow computers for while. This is seen especially dialogs with animation on it.

Hope you got idea :)

Cheers!
Posted

1 solution

Hi,

Please take into consideration that the Loaded event takes place on the same thread as the UI. Thus, if the
C#
GetDataFromDatabase()
and
C#
MakeCalculations()
are a long running operations, the UI will be non responsive during this time.

You could make use of asynchronous operations. Please have a look at the following:

Responsive UIs for WPF Applications Using Asynchronous Processing[^]
Build More Responsive Apps With The Dispatcher[^]

Kind regards,
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900