Here is some sample code to better illustrate what I am trying to accomplish here. Basically I need to set property which can only be set from UI thread. Any ideas?
public ref class ExtendedImage : public System::Windows::Controls::Image
{
public:
void SetImageFromUrl (System::String^ url)
{
if (!System::Uri::TryCreate (path, System::UriKind::Absolute, this->m_uri) || this->m_uri->IsFile)
return;
System::Threading::Thread^ downloadImage = gcnew System::Threading::Thread (gcnew System::Threading::ThreadStart (this, &ExtendedImage::DownloadAndSetImage));
downloadImage->Start ();
}
private:
System::Uri^ m_uri;
void DownloadAndSetImage ()
{
System::Windows::Media::Imaging::BitmapImage^ bitmap = gcnew System::Windows::Media::Imaging::BitmapImage (this->m_uri);
//execute this->Source = bitmap; on UI thread
}
}
Update:
A bit of useful information after combining question code to correct answer C# solution. To get UI thread Dispatcher use System::Windows::Application::Current->Dispatcher
.