The calling thread must be STA, because many UI components require this

Stevan
Stevan
312 Points
20 Posts

I'm try to focus on browse button through following code

if (!System.IO.Directory.Exists(MergeFilePath))
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Please select Destination Folder", "Select Destination Folder", System.Windows.MessageBoxButton.OK);
                btnChangeDestinationPath.Focus();
            }
  <Button Name="btnChangeDestinationPath" Width="75" Click="btnChangeDestinationPath_Click">Change</Button>

I'm getting following error:

"The calling thread must be STA, because many UI components require this."

{Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation.}

 

Views: 18655
Total Answered: 1
Total Marked As Answer: 0
Posted On: 25-Aug-2018 19:35

Share:   fb twitter linkedin
Answers
Smith
Smith
2890 Points
78 Posts
         

Use following code:

Application.Current.Dispatcher.Invoke((Action)delegate
                {
                    btnChangeDestinationPath.Focus();
                });
Posted On: 28-Aug-2018 08:12
 Log In to Chat