I currently ran into the issue of making my Windows Phone application performing a cross-thread operation.
In the defualt C# [Windows Form Application], there is an option / variable called "CheckForIllegalCrossThreads" - If you set this variables property to "False" the application no longer checks for illegal cross threads durning runtime action.
Actual Question: Does this variable exist under another name in a silverlight windows phone application project?
Update: [Issue solved, thanks to Jon Skeet]
For other people whose looking for a way to solve this issue, or a simmilar issue: I solved this issue using [as mentioned above] "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...";
);
}
Actual Question: Does this variable exist under another name in a silverlight windows phone application project?
Even if it did, you shouldn't use it. Setting the value to false isn't the right thing to do under Windows Forms, either.
If the "low fuel" light in your car comes on, do you disconnect it, or do you refuel your car? The same applies here: fix the problem, not the warning. Don't access UI elements directly other than from the UI thread. Use Control.Invoke
/BeginInvoke
in Windows Forms, or Dispatcher.Invoke
/BeginInvoke
in WPF/Silverlight to marshal execution to the UI thread.