Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以进行异步InitializeComponent?否则我可以异步加载我的 WPF 组件吗?更具体地说,我目前正在 WPF 中开发产品,我注意到当我有性能要求时,图形组件(某些组件)的加载时间相当长。
InitializeComponent
如果您在 UI 线程上创建组件,则无法将其InitializeComponent放在另一个线程上,但可以使用Dispatcher.BeginInvoke以下方式在同一线程中异步调用它:
Dispatcher.BeginInvoke
Dispatcher.BeginInvoke(new Action(() =>InitializeComponent()));