I have a button that starts my camera. I want to sometimes start the camera dinammicly threw code, without pressing the button.
the code:
private async void StartCamera()
{
    if (!CameraList.HasItems) //-------> CameraList is in the UI
    {
        MessageArea.Text = "No cameras found; cannot start processing";
        return;
    }
    // Clean leading/trailing spaces in API keys. 
    Properties.Settings.Default.FaceAPIKey = Properties.Settings.Default.FaceAPIKey.Trim();
    Properties.Settings.Default.EmotionAPIKey = Properties.Settings.Default.EmotionAPIKey.Trim();
    Properties.Settings.Default.VisionAPIKey = Properties.Settings.Default.VisionAPIKey.Trim();
    // Create API clients. 
    _faceClient = new FaceServiceClient(Properties.Settings.Default.FaceAPIKey);
    _emotionClient = new EmotionServiceClient(Properties.Settings.Default.EmotionAPIKey);
    _visionClient = new VisionServiceClient(Properties.Settings.Default.VisionAPIKey);
    // How often to analyze. 
    _grabber.TriggerAnalysisOnInterval(Properties.Settings.Default.AnalysisInterval);
    // Reset message. 
    MessageArea.Text = ""; // -------> MessageArea is in the UI
    // Record start time, for auto-stop
    _startTime = DateTime.Now;
    await _grabber.StartProcessingCameraAsync(CameraList.SelectedIndex); // This is the problem, with the previous two I just can skip it, but here I can't avoid the CameraList
}
private async void StartButton_Click(object sender, RoutedEventArgs e)
{
    StartCamera();
}
I must tell that the CameraList variable is a UI combobox.
So when I try to use the StartCamera function I get an exception that says {"The calling thread cannot access this object because a different thread owns it."}
The same thing happnes when I try to use the startButton UI and using:
    StartButton.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent));
in a previous thread I was told: "You can only access a UI element from the thread on which it was originally created, i.e. the UI thread. So you cannot run your code on a background thread. This has nothing to do with your original question about how to invoke the event handler though. Please ask a new question if you have another issue."
So here I am.
 
     
    