我一直在开发一个消耗Windows运行时组件(WRC)的Windows Phone应用程序。由非UI线程访问的功能需要使用访问Windows手机应用程序的回调。
void WControlPointCallback::OnListChange(char *pFriendlyName)
{
// Callback function to access the UI
pCallBack->AlertCaller("Message");
}
首先不使用调度程序,它抛出
Platform::AccessDeniedException
。
然后我提到this,this和this。 我试图从UI中获取Dispatcher。
var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
它扔了System.AccessViolationException
。然后我用了
pDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
在C ++代码(WRC)中。但这也引发了Platform::AccessDeniedException
。
如何在Windows Phone中获取UI的Dispatcher?
答案 0 :(得分:11)
您无法从C ++ for Windows Phone 8获取调度程序:您需要将调用移至C#端的UI调度程序,而不是C ++端。
如果你能做这样的事情:
class DotNetClass : IWindowsRuntimeInterface
{
void AlertCaller(string message)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(message);
}
}
}