Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance concern while opening a dialog repetitively in wpf

I have a launch dialog button which creates a view model of a window and bind it to the the window(it is having UI virutalization enabled). It takes only 1 second to launch the dialog at first click. But if I open the same dialog very frequently or back to back, it starts taking more time in populating the grid data source for next iteration. if I give some pause, then again open window, then it takes only approx 1 or 2 seconds.

for first time populating the item source it take only 1 second:
next time populating the item source it takes  2 second
next time populating the item source it takes  3 second
next time populating the item source it takes  6 second
next time populating the item source it takes  8 second

However, if I call GC.Collect() which is not recommended, then populating grid data source always takes approx 1 second. but calling of

Gc.Collect()
Gc.WaitForPendingFinalizer()
Gc.Collect()

cost me some time for every iteration.

I know calling GC.Collect is not a good option. Can anybody suggest how can I boost my application performance.

I am more concerned about the user machine as my machine is with very good configuration whereas user machine may not so fast.

like image 371
Yogesh Avatar asked Feb 08 '16 08:02

Yogesh


People also ask

Why is WPF application slow in performance?

The unnecessary elements in the visual tree also contribute to the slowness of WPF applications. You should ideally combine the layout and optimize the default control templates.

Which dialog box does not prevent a user from activating other windows while it is open?

The most common dialog boxes are used to show an open file or save file prompt, displaying the printer dialog, or messaging the user with some status. A modeless dialog box doesn't prevent a user from activating other windows while it's open.


1 Answers

It is difficult to pinpoint the exact issue without looking at the code. However, usually this can happen due to a few reasons.

  1. It loads more data (may be double?) evertime. You have indicated it loads only 200 records everytime. But make sure your logic is correct and it clears previous data before you re-publish.

  2. Make sure you unsubscribe from any event subscriptions. Sometimes there can be hiden events triggering for previous grid instances. You can easily check that by putting a break on an even handle and checking if it trigger more than once.

  3. Look at every Disposable instances you are creating and check if you dispose them appropriately. Probably you are not disposing disposable instance and that may be the reason that GC.Collect help.

  4. I am not quite sure about virtualization involvement here. Perform the same test without virtualization to make sure that's not the reason.

like image 159
CharithJ Avatar answered Oct 12 '22 23:10

CharithJ