在Windows 8手机UI获取调度 [英] Obtaining UI dispatcher in Windows phone 8
问题描述
我一直在开发消耗由非UI线程访问Windows运行时组件(WRC)。一个功能,需要使用访问Windows Phone应用程序的回调一个Windows Phone应用程序。
I have been developing a Windows Phone application that consumes Windows Runtime component(WRC).A function accessed by a non-UI thread,needs to use a callback that access the Windows phone application.
void WControlPointCallback::OnListChange(char *pFriendlyName)
{
// Callback function to access the UI
pCallBack->AlertCaller("Message");
}
起初不使用分派扔
At first without using the Dispatcher it threw
平台:: AccessDeniedException异常
。
Then I referred to this, this and this. I tried to obtain the Dispatcher from the UI.
var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
它扔 System.AccessViolationException
。然后我使用
pDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
在C ++代码(WRC),而这也将引发平台:: AccessDeniedException异常
。
in C++ code(WRC).But this too throws Platform::AccessDeniedException
.
如何获取调度的UI在Windows Phone的?
How to obtain the Dispatcher for UI in Windows Phone?
推荐答案
您无法从C ++调度程序的Windows Phone 8的:你需要将呼叫转移到C#的一面,而不是C ++端UI调度
You can't get the dispatcher from C++ for Windows Phone 8: you need to move the call to the UI dispatcher on the C# side, not the C++ side.
如果你可以做这样的事情:
If you can just do something like this:
class DotNetClass : IWindowsRuntimeInterface
{
void AlertCaller(string message)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(message);
}
}
}
这篇关于在Windows 8手机UI获取调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!