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 3454844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:32:29+00:00 2026-05-18T09:32:29+00:00

I’m fairly new to working with threads. I was trying to set a DependencyProperty

  • 0

I’m fairly new to working with threads. I was trying to set a DependencyProperty‘s value:

    public States State
    {
        get { return (States)GetValue(StateProperty); }
        set
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Background,
                //(SendOrPostCallback)delegate { SetValue(StateProperty, value); }, //works
                (Action)(()=> SetValue(StateProperty, value)), //doesnt
                value);
        }
    }
    public static readonly DependencyProperty StateProperty =
        DependencyProperty.Register("State", typeof(States), typeof(FTPDownload), new UIPropertyMetadata(States.Idle));

I realized the hard way that in the setter you have to use SendOrPostCallback (as it provides an argument when calling the method). it does NOT work with Action (because of the missing argument. And, wpf is really a bitch about it, debugging and finding the cause of the TargetParameterCountException with “no source available” and no clue at all.

Why do I have to use SendOrPostCallback there? and how should I know that in this case this is the right one? Because actually calling the setter works via:

Dispatcher.BeginInvoke((Action)(()=>State=States.Updating), null);

and using the SendOrPostCallback instead of course results in a TargetParameterCountException..

Just wondering if seemingly inconsistent thing like that are just common knowledge? Feeling a bit lost here, at least since googling around with SendOrPostCallback, Action and BeginInvoke as keywords had no meaningful results.

  • 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-18T09:32:30+00:00Added an answer on May 18, 2026 at 9:32 am

    The relevant pieces of information:

    1.The overload of Dispatcher.BeginInvoke that you are using is:

    public DispatcherOperation BeginInvoke(
        DispatcherPriority priority,
        Delegate method,
        Object arg
    )
    

    method: A delegate to a method that takes one argument, which is pushed onto the Dispatcher event queue.

    2.The SendOrPostCallBack delegate is declared as:

    public delegate void SendOrPostCallback(object state)
    

    3.As for Action:

    public delegate void Action()
    

    Clearly, the SendOrPostCallBack delegate is compatible since it takes a single argument but Action is not, since it is parameterless.

    Of course, you can use the Action<T> delegate, which does take a single argument, if you prefer:

    Dispatcher.BeginInvoke(DispatcherPriority.Background,
                            new Action<States>(arg => SetValue(StateProperty, arg)),
                            value);
    

    Alternatively, you can use a different overload of Dispatcher.BeginInvoke that expects an argument that is of a delegate-type that takes no arguments, and get the C# compiler to do the dirty work for you in the closure:

    Dispatcher.BeginInvoke(DispatcherPriority.Background,
                            new Action(() => SetValue(StateProperty, value));
    

    Notice that value is a captured variable, so please be careful.

    (Also, this answer doesn’t deal with any thread-safety issues, only about the delegate signatures involved.)

    • 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.