在 Windows Phone 8 中获取 UI 调度程序
本文关键字:获取 UI 调度程序 Windows Phone | 更新日期: 2023-09-27 18:34:27
我一直在开发一个使用Windows运行时组件(WRC)的Windows Phone应用程序。由非 UI 线程访问的函数,需要使用访问 Windows Phone 应用程序的回调。
void WControlPointCallback::OnListChange(char *pFriendlyName)
{
// Callback function to access the UI
pCallBack->AlertCaller("Message");
}
起初没有使用调度程序,它抛出了
Platform::AccessDeniedException
.
然后我提到了这个,这个和这个。我试图从 UI 获取调度程序。
var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
它扔了System.AccessViolationException
.然后我用了
pDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
在C++代码(WRC)中。但这也抛出了Platform::AccessDeniedException
.
如何在 Windows Phone 中获取 UI 调度程序?
无法从 Windows Phone 8 的C++获取调度程序:需要将调用移动到 C# 端的 UI 调度程序,而不是C++端。
如果你可以做这样的事情:
class DotNetClass : IWindowsRuntimeInterface
{
void AlertCaller(string message)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(message);
}
}
}