I have a WPF application that will set an image source when a button is clicked
I want to then clear the image source after so many seconds, say 15 seconds have passed.
How can I do this?
I have tried to use Thread.sleep but it clears the source right away then just pauses the application for the 15 seconds
here is what i have for that method
private void btnCapture_Click(object sender, RoutedEventArgs e)
{
imgCapture.Source = //my image source;
Thread.Sleep(15000);
imgCapture.Source = null;
}
I have also tried
private void btnCapture_Click(object sender, RoutedEventArgs e)
{
imgCapture.Source = //my image source;
imgCapture.Source = null;
Thread thread = new Thread(new ThreadStart(clearSource));
thread.Start();
}
private void clearSource()
{
Thread.Sleep(15000);
imgCapture.Source = null;
}
but I get an error saying The calling thread cannot access this object because a different thread owns it.
How can I get that image source to clear after 15 seconds.
Thanks!
Use a DispatcherTimer: