我有一个启动对话框按钮,它创建了一个窗口的视图模型并将其绑定到窗口上(它启用了UI虚拟化)。第一次点击启动对话框只需要1秒钟。但是,如果我非常频繁地或连续打开同一个对话框,下一次迭代中填充网格数据源就开始花费更多的时间。如果我暂停一下,然后再次打开窗口,那么大约只需要1或2秒钟。
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
然而,如果我调用不建议使用的GC.Collect()方法,那么填充网格数据源始终需要大约1秒钟。但是调用
Gc.Collect()
Gc.WaitForPendingFinalizer()
Gc.Collect()
每次迭代都会花费我一些时间。
我知道调用 GC.Collect
不是一个好的选择。有人可以建议如何提高我的应用程序性能吗?
我更关注用户机器,因为我的机器配置非常好,而用户机器可能没有那么快。