是否存在與WPF中的Form.InvokeRequired等效的Dispatcher.InvokeRequired?等價於WPF中的InvokeRequired
7
A
回答
5
,因爲它沒有在智能感知出現,這是有點奇怪,但你可以使用:
var dispatcher = myDispatcherObject.Dispatcher;
if (dispatcher.CheckAccess()) { /* ... */ }
由於所有UI組件繼承從DispatcherObject
這應該解決您的具體問題,但它不是特定於UI線程 - 它可以用於任何調度程序。
3
來考慮可能的解決方案是:
if (Dispatcher.Thread.Equals(Thread.CurrentThread))
{
Action();
}
else
{
Dispatcher.Invoke(Action);
}
4
0
如果您正在構建Windows應用商店應用,則上述示例將不起作用。這裏有一個例子,確實工作。根據需要修改當然:)
/// <summary>
/// Updates the UI after the albums have been retrieved. This prevents the annoying delay when receiving the albums list.
/// </summary>
/// <param name="albums"></param>
public void UpdateUiAfterAlbumsRetrieved(System.Collections.ObjectModel.ObservableCollection<PhotoAlbum> albums)
{
if (!Dispatcher.HasThreadAccess)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
ddlAlbums.DataContext = albums;
ddlAlbums.IsEnabled = true;
tbxProgress.Text = String.Empty;
ProgressBar.IsIndeterminate = false;
ProgressBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
});
}
else
{
ddlAlbums.DataContext = albums;
ddlAlbums.IsEnabled = true;
tbxProgress.Text = String.Empty;
ProgressBar.IsIndeterminate = false;
}
}
相關問題
- 1. WPF等價於ActiveControl?
- 2. WPF等價於TextRenderer
- 3. Application.ProductName等價於WPF?
- 4. RepositionThemeTransition等價於WPF
- 5. WPF等價於Flex狀態
- 6. WPF中的PagedCollectionView等價物?
- 7. WPF中BeginUpdate的等價物?
- 8. 什麼是WPF等價於ControlPaint.Light?
- 9. 如何在WPF中使用InvokeRequired?
- 10. WPF中的WinForms ComboBox.DroppedDown的等價示例
- 11. CakePHP中的HttpSocket等價於
- 12. 等價於.NET中的System.currentTimeMillis()?
- 13. 等價於R中的normxcorr2?
- 14. 等價於Julia中的pickle
- 15. 等價於AngularJS中的location.href.match
- 16. 等價於C++中的C++
- 17. 等價於D中的remove_if
- 18. WPF中的WinForms ListView.FullRowSelect等價物
- 19. 等價於BN_hex2bn
- 20. 等價於getbounds
- 21. 等效於WPF中的TransparencyKey
- 22. 在php中等價於memcpy
- 23. wpf mvvm等於
- 24. Solaris中的「installf」等價於Linux中的
- 25. `expect_any_instance_of`等價於PHPUnit
- 26. C++等價於Tidy
- 27. Scala等價於java.util.Collection?
- 28. iPad等價於onmousemove?
- 29. SizeToContent等價於WinForm?
- 30. jconsole等價於.Net?