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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:46:20+00:00 2026-06-17T11:46:20+00:00

I have a class that manages the UI, which contains this method: public void

  • 0

I have a class that manages the UI, which contains this method:

public void SetField(int field, int value)

I have a delegate declared:

public delegate void SetFieldDelegate(int field, int value);

On a buttonpress event, I call a computationally expensive method of another class, on a background thread. The UI doesn’t freeze, the work is being done. On occasion, I want to update the UI though, I tried to use the delegate for this, to avoid cross-thread operations:

Gui.SetFieldDelegate TestDelegate = new Gui.SetFieldDelegate(gui.SetField);

In the heavy working method, I call:

TestDelegate.Invoke(field, value);

But it’s still an invalid cross-thread opeartion. I’m sure it’s something trivial, but I’m lost. Also, any suggestions are welcome, if there is a much easier way to do this.

  • 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-06-17T11:46:22+00:00Added an answer on June 17, 2026 at 11:46 am

    You’re calling Invoke on the delegate, which doesn’t do anything about threads – it’s just invoking it synchronously.

    You need to call Invoke on an element of the UI, e.g.

    form.Invoke(TestDelegate, value);
    

    or BeginInvoke instead:

    form.BeginInvoke(TestDelegate, value);
    

    That’s assuming you’re using Windows Forms. If you’re using WPF or Silverlight, you need to use Dispatcher.Invoke or Dispatcher.BeginInvoke instead, e.g.

    form.Dispatcher.BeginInvoke(TestDelegate, value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class that looks like this: class A { public: class variables_map vm
I have an interface IRenderable and a class that manages rendering all instances of
Im making a program for class that manages a Hotel. I have a function
I have a GUI tool that manages state sequences. One component is a class
I have class A such that: class A { static int i; A(); f1();
My class contains an object from Interop and calls a method on it which
I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE,
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
I have an Assembly(A) which defines a Managed class which has a public constructor
I have created a class that will manage connection and commands, I named it

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.