I have created a thread, but the thread pauses the main process after I start it. The thread loads some images from google, but when the internet connection is lost the user interface is unusable.
This is the thread:
string searchWord = "car photo";
PhotoSearchThread = new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
if (!string.IsNullOrWhiteSpace(searchWord))
{
string html = GetHtmlCode(searchWord);
SearchedImagesUrls = GetUrls(html);
this.Dispatcher.Invoke(() =>
{
if (SearchedImagesUrls.Count > 0)
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(SearchedImagesUrls[0]);
image.EndInit();
SelectPhotoImage.Source = image;
}
});
}
});
PhotoSearchThread.Start();
Well threads should run simultaneously, then why this thread is interrupting other threads?