CheckForIllegalCrossThreads, Thread & Delegate - Window

本文关键字:Delegate Window amp Thread CheckForIllegalCrossThreads | 更新日期: 2023-09-27 18:33:13

我目前遇到了使Windows Phone应用程序执行跨线程操作的问题。
在 defualt C# [Windows 窗体应用程序] 中,有一个名为"CheckForIllegalCrossThreads"的选项/变量 - 如果将此变量属性设置为"False",则应用程序在运行时操作期间不再检查非法交叉线程。

实际问题:此变量是否以 Silverlight Windows Phone 应用程序项目中的另一个名称存在?

更新:[问题已解决,感谢乔恩·斯基特]

对于正在寻找解决此问题的方法或类似问题的其他人:我使用[如上所述]"Dispatcher.BeginInvoke"解决了此问题

Thread myThread;
public MainPage()
    {
        InitializeComponent();
        myThread = new Thread(ThreadPromt);
        myThread.Start();
    }
Private void ThreadPromt()
{
Dispatcher.BeginInvoke(deleage(
     MessageBox.Show(string.Format("Accessed from another thread: {0}", SampleLabel.Text);
     ButtonSample.Text = "Accessed from another thread...";
);
}

CheckForIllegalCrossThreads, Thread & Delegate - Window

实际问题:此变量是否以 silverlight Windows Phone 应用程序项目中的另一个名称存在?

即使有,你也不应该使用它。将值设置为 false 也不是在 Windows 窗体下正确的做法。

如果你的车里的"低油"灯亮了,你是断开它,还是给你的车加油?这同样适用于这里:修复问题,而不是警告。不要直接从 UI 线程访问 UI 元素。在 Windows 窗体中使用 Control.Invoke/BeginInvoke,或在 WPF/Silverlight 中使用 Dispatcher.Invoke/BeginInvoke 将执行封送到 UI 线程。