Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 669293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:08:07+00:00 2026-05-14T00:08:07+00:00

I’m writing a WPF application and trying to bind an image to my view

  • 0

I’m writing a WPF application and trying to bind an image to my view model with the following XAML:

<Image Source="{Binding Author.IconUrl, IsAsync=True}" />

The problem is that the image URLs are defined by users and can often refer to images hosted on intranet web servers. When the WPF application is run remotely, it locks up while trying to resolve the images that are now unreachable.

I thought the “IsAsync” binding property would cause the load to happen in the background, but it appears that the DNS resolution may still happen in the main thread?

What can I do to keep my app from locking, even if the images are unreachable?

Thanks,
Corey

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:08:08+00:00Added an answer on May 14, 2026 at 12:08 am

    Here is a new answer for you, hopefully better than my earlier one.

    When you create your binding with ‘IsAsync’ true, it executes the property access to Author.IconUrl on a separate thread but does the conversion from Uri to ImageSource in the main thread. As you discovered, the conversion does a DNS lookup on the main thread causing the application to lock up.

    Since your source is http/https, WPF will automatically handle asynchronously loading the image source. So I suspect all you need to do is to make just the DNS lookup asynchronous.

    This can be automated by using an attached property:

    <Image my:ImageAsyncHelper.SourceUri="{Binding Author.IconUrl}" />
    

    where ImageAsyncHelper is defined as:

    public class ImageAsyncHelper : DependencyObject
    {
      public static Uri GetSourceUri(DependencyObject obj) { return (Uri)obj.GetValue(SourceUriProperty); }
      public static void SetSourceUri(DependencyObject obj, Uri value) { obj.SetValue(SourceUriProperty, value); }
      public static readonly DependencyProperty SourceUriProperty = DependencyProperty.RegisterAttached("SourceUri", typeof(Uri), typeof(ImageAsyncHelper), new PropertyMetadata
      {
        PropertyChangedCallback = (obj, e) =>
        {
          ((Image)obj).SetBinding(Image.SourceProperty,
            new Binding("VerifiedUri")
            {
              Source = new ImageAsyncHelper { GivenUri = (Uri)e.NewValue },
              IsAsync = true,
            });
        }
      });
    
      Uri GivenUri;
      public Uri VerifiedUri
      {
        get
        {
          try
          {
            Dns.GetHostEntry(GivenUri.DnsSafeHost);
            return GivenUri;
          }
          catch(Exception)
          {
            return null;
          }
    
        } 
      } 
    }
    

    The way this works is:

    1. When you set the attached property it creates an instance of an ImageAsyncHelper and asynchronously binds the Image.Source to the ImageSource propety of the async helper object.
    2. When the asynchronous binding fires it calls the VerifiedUri getter which verifies the address is accessible then returns the GivenUri
    3. If your IconUri property ever changes, the binding causes the attached property to update which creates and binds a new ImageAsyncHelper so the images stays up to date.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.