简体   繁体   English

Windows Phone C ++

[英]Windows phone C++

I'm writing simple application for WP 8.1 using C++/cx. 我正在使用C ++ / cx编写WP 8.1的简单应用程序。 My problem starts when I'm trying to do something in some event. 当我在某些情况下尝试做某事时,我的问题就开始了。 For example if I create simple button event "tapped" and I want to do something inside for example change the color of the button background, it doesn't execute in the correct time. 例如,如果我创建一个简单的按钮事件“轻按”,并且想要在内部做一些事情(例如更改按钮背景的颜色),那么它将无法在正确的时间执行。 I mean that for the code below it will first execute Somefunction() and then change the color of the button.Same happens for example when I try to show message box using message dialog and ShowAsync function. 我的意思是对于下面的代码,它将首先执行Somefunction()然后更改按钮的颜色。例如,当我尝试使用消息对话框和ShowAsync函数显示消息框时,也会发生同样的情况。

but->Background = ref new SolidColorBrush(Windows::UI::Colors::Red);
Somefunciton();

You have the background change and the function call in the same function and that function gets executed on one thread blocking it. 您在同一函数中进行了后台更改和函数调用,并且该函数在阻止它的一个线程上执行。 This thread happens to be the UI thread which gets blocked for the time of your function execution. 该线程恰好是UI线程,在执行函数时被阻塞。 So you set the button background but the actual change will be applied only when the UI thread could run the render function and it will be able to do it only after your function call ends. 因此,您设置了按钮背景,但是只有在UI线程可以运行render函数时才应用实际更改,并且只有在函数调用结束后才能执行更改。

So in terms of program execution the button background gets updated before the call to Somefunciton(); 因此,就程序执行而言,在调用Somefunciton();之前,按钮背景已更新Somefunciton(); . But visual changes are delayed until after the function call is completed so you might think that Somefunciton(); 但是视觉更改会延迟到函数调用完成之后,因此您可能会认为Somefunciton(); gets called before the background is set which is not the case. 在设置背景之前被调用,情况并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM