最小化 WPF 中的对话框加载时间
我有一个包含两个控件的对话框 a) 组合框和 b) 图形控制。
当对话框初始化时,组合框包含 10 个项目。
假设对于每个项目更改,我必须读取大数据点并将它们绘制到图形控件中。每个项目更改的整个活动大约需要 10 秒。
有两种情况:
当我双击对话框时,组合框的选择更改也会触发,最终在加载对话框时读取大数据并将其绘制到图形控件中。由于该对话框需要花费大量时间才能出现。
此外,当我在组合框中进行选择更改时(启动对话框时),它将再次读取数据。但是,当对话框已经启动时,我将在单独的线程上执行此活动。
但我的问题是如何最大限度地减少第 1 点 中的对话框加载时间?我需要最大限度地减少对话框加载时间。
请帮忙!!1
I have a dialog box which consist two controls
a) combo box and
b) Graph control.
When dialog is initialized the combo box contain 10 items.
Let's say for each item change I have to read large data point and plot them into a graph control. This whole activity per item change takes around 10 seconds.
There are two cases:
When I double click the dialog box the selection change of combo box will also fired which eventually reads the large data while loading a dialog and plot it into graph control. Due to which dialog takes lot of time to come up.
Further more when I do the selection change in combo box (when dialog is launched) it will read the data again. However I will do this activity on a seprate thread when dialog is already launched.
But my question is how can I minimize dialog loading time in point 1 ? I need to minimize the dialog loading time.
Please help!!1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很难理解第 1 点到底发生了什么 - 对话框是否关闭,您按下主窗口中的按钮打开对话框,现在打开对话框需要很长时间?或者对话框是否已经打开,您双击它,现在速度很慢(这没有意义,因为这应该是第 2 点...)?
无论如何,如果我理解正确并且您的主要问题是,在打开对话框时您还加载图表,这会导致对话框在 10 秒后显示,那么这就是您需要做的:
在对话框窗口中 < code>Loaded() 事件处理程序填充您的组合框并设置其选定索引(设置为适当的值,例如 0)。在组合框
SelectedIndexChanged
事件处理程序中创建一个获取图形数据的后台线程,完成后更新您的对话框窗口(例如this.Dispatcher.调用(...)
)。虽然我不明白你为什么还没有通过实施第 2 点来做到这一点......
I'm having a bit of hard time understanding what exactly is going on in point 1 - is the dialog closed, your press a button in your main window that opens the dialog, now opening the dialog takes a long time? Or is the dialog already open, you double click in it, and now it's slow (this doesn't make sense, because this should be point 2...)?
Anyway, if I'm understanding correctly and your main problem is, that upon opening your dialog you also load the graph, which causes the dialog to show up 10 seconds later, then this is what you need to do:
In the Dialog window
Loaded()
event handler populate your combobox and set its selected index (to whatever is apropriate, eg. 0). In the comboboxSelectedIndexChanged
event handler create a background thread that gets the graph data, and once it is done, update your Dialog window (eg.this.Dispatcher.Invoke(...)
).Although I don't understand how come you haven't done this already by implementing point 2...