第二次访问页面时,我的函数中的某些代码无法运行 [英] Certain code in my function doesn't run when visiting a page a second time

查看:71
本文介绍了第二次访问页面时,我的函数中的某些代码无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用套接字构建应用程序,当我第一次访问"thepage.xaml"时,我的应用程序会完美地收到信息。但是当我回到菜单然后访问"thepage.xaml"时再次,某些代码不会运行。


我知道代码本身不是问题,否则页面第一次无法正常工作。没有变量可以改变代码的执行方式。我已经添加了MessageBoxes以确保正在运行这些函数,并且我是
在屏幕上弹出消息,但函数中的其余代码没有运行。

 private void testing()
{
myboolean = true;
notificationTextBlock.Text ="选择你的行动..." ;;
MessageBox.Show("应该刚刚排序了stuf ...");
}

这是应该运行的代码,我收到消息框正常,但其余代码不是正在执行......为什么会这样!?




请记住这段代码在我第一次运行页面时工作正常,但是当我回到我的应用菜单区域时回到页面,它没有运行前两行,只是消息框......



谢谢,


Jamie:)

解决方案

无法执行部分代码。  我倾向于认为你试图从错误的线程更新ui,因此文本块没有更新。


 private void testing()
{
myboolean = true;




Dispatcher.BeginInvoke(()=> {
//此代码位于UI线程上.admuniceTextBlock.Text ="选择你的行动......";
});
MessageBox.Show("应该刚刚排序了stuf ...");
}




 


Hi,

I am building an application using sockets and my app recieves information perfectly when i first visit "thepage.xaml" but when i go back to the menu and then visit "thepage.xaml" again certain bits of code do not run.

I know the code itself isn't the problem otherwise the page wouldn't work correctly the first time. There are no variables to this that could change the way the codes execute. I had added MessageBoxes to make sure that the functions are being run and i am getting the messages popping up on the screen but the rest of the code in the functions is not being run.

        private void testing()
        {
            myboolean = true;
            notificationTextBlock.Text = "Choose your move...";
            MessageBox.Show("should have just sorted stuf...");
        }

This is the code that should be running and i am getting the messagebox fine but the rest of the code is not being executed... why is this!?


REMEMBER this code works fine the first time i run the page but when going back to my apps menuarea and back into the page, it doesn't run the first two lines, just the messagebox...

Thanks,

Jamie :)

解决方案

There is no way that part of the code is not being executed.   What I tend to think is that you are trying to updated the ui from the wrong thread so the textblock is not updating.

        private void testing()
        {
            myboolean = true;
           
 


Dispatcher.BeginInvoke( () => {
   // This code is on the UI thread. notificationTextBlock.Text = "Choose your move...";
});
           MessageBox.Show("should have just sorted stuf...");
        }




这篇关于第二次访问页面时,我的函数中的某些代码无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆