DotNet/Answer Detail

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

Stevan
Stevan
12 Points
6 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.}

 

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

Share:   fb twitter linkedin
Answers
Smith
Smith
Participant
346 Points
103 Posts
     

Use following code:

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

Blog

Active User (2)

 Log In to Chat