I have this 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;
// This is the problem, with the previous two I just can skip it,
// but here I can't avoid the CameraList
await _grabber.StartProcessingCameraAsync(CameraList.SelectedIndex);
}
private async void StartButton_Click(object sender, RoutedEventArgs e)
{
StartCamera();
}
I want to the functionallity of StartButton to happen threw code, without me actually clicking it. The problem is that it is in the UI thread so I get an exception. I wastold that I should use Dispacher.Invoke for it but I am having a lot of troble doing so.
Is there a simple way to just invoke the button at run-time ?
Thanks