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

  • SEARCH
  • Home
  • 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 7584319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:53:30+00:00 2026-05-30T18:53:30+00:00

I’m so frustrated trying to solve this. Why is creating threads and updating UI

  • 0

I’m so frustrated trying to solve this. Why is creating threads and updating UI after completing them so complicated?! I have tried this, this and this and I still can’t get my head around the whole multi-threading thing clearly at all. It was so easy in Java…

Anyway here’s a simplified version of my code as the result of third link:

private delegate void SimpleDelegate2(BitmapImage bi);
private delegate void SimpleDelegate(string st1, string st2);

private void Process(string st1)
{
    try
    {
        string st2 = "test st2";
        SimpleDelegate del = new SimpleDelegate(LongRunningProcess);
        del.BeginInvoke(st1, st2, null, null);
    }
    catch
    {
        //do some failsafe thing
    }
}

private void LongRunningProcess(string st1, string st2)
{
    //do some long processing with the strings
    BitmapImage bi = new BitmapImage();//there will be an actual bitmap here

    SimpleDelegate2 del1 = delegate(BitmapImage bimg)
    {
        ImageControlOnWPFform.Source = bimg; //null;
    };
    this.Dispatcher.BeginInvoke(DispatcherPriority.Send, del1, bi);
}

The problem here is that I can’t set the Source value of the Image control to bimg but I can set it to null! Whenever I try to set it to bimg I get the exception that says the calling thread cannot access this object because a different thread owns it. I have also tried setting it directly to bi which also gives the same exception.

But I can set the source to null without any problem, which means I can modify the Source value of the Image control. But how do I access bi or bimg? Am I doing something wrong?

Also: I notice that the given arguments of the last BeginInvoke do not match any overload of the method but they are still accepted as valid and works properly. When I point at BeginInvoke I am shown a completely different set of method overloads than the ones that appear when I type a ( following the method name. Why?

  • 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-30T18:53:32+00:00Added an answer on May 30, 2026 at 6:53 pm

    Answer for main question

    Execute bi.Freeze() before using the BitmapImage in the UI thread. The Freeze operation will make the BitmapImage read-only and thread-safe.

        ...
        //do some long processing with the strings
        BitmapImage bi = new BitmapImage();//there will be an actual bitmap here
        bi.Freeze();
    
        SimpleDelegate2 del1 = delegate(BitmapImage bimg)
        ...
    

    Answer for Also

    The class System.Windows.Threading.Dispatcher has five signatures for the BeginInvoke method:

    public DispatcherOperation BeginInvoke(Delegate method, params object[] args);
    public DispatcherOperation BeginInvoke(DispatcherPriority priority, Delegate method);
    public DispatcherOperation BeginInvoke(Delegate method, DispatcherPriority priority, params object[] args);
    public DispatcherOperation BeginInvoke(DispatcherPriority priority, Delegate method, object arg);
    public DispatcherOperation BeginInvoke(DispatcherPriority priority, Delegate method, object arg, params object[] args);
    

    However, three of the signatures (those with DispatcherPriority priority as their first argument) have the following tags on them:

    [Browsable(false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    

    This is why they do not show up when typing a ( after the method name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

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.