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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:07:04+00:00 2026-05-16T03:07:04+00:00

For example, I’ve got a business object Person : class Person : INotifyPropertyChanged {

  • 0

For example, I’ve got a business object Person:

class Person : INotifyPropertyChanged
{
    string Name { get; set; }
    DateTime DateOfBirth { get; set; }
}
// ^ abbreviated for better legibility; implementation would be trivial

And I’ve got some Winforms UI controls data-bound to an object of this class:

Person somePerson = ...;
nameTextBox.DataBindings.Add("Text", somePerson, "Name");
dobDatePicker.DataBindings.Add("Value", somePerson, "DateOfBirth");

Now I am making changes to somePerson and thanks to having INotifyPropertyChanged implemented, those changes are reflected in the UI. So far so good.

Now to my problem: If I make changes to somePerson in a worker thread (ie. not in the UI thread), e.g. because I’m loading data from a DB as a background operation, this might cause exceptions because the data binding attempts to update the controls, which is only allowed to happen on the UI thread.

This means that I need to call InvokeRequired on a UI element to see if I’m allowed to update a business object — which seems like a violation of the application’s logical layering.

Ideally, I want to be able to modify my business objects without having to care whether it is data-bound to the UI or not. Is this somehow possible with Winforms data binding, or not?

  • 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-16T03:07:05+00:00Added an answer on May 16, 2026 at 3:07 am

    This doesn’t answer your question, but I try as far as possible to avoid this problem.

    Because of the existence of data binding, I make sure the only code that can update business objects is code that’s running on the GUI thread.

    For async operations, I adopt a pattern of:

    1. Send work to the background: Trigger an async operation — say, a thread pool item — from the GUI thread. Pass only plain data types into the thread pool, and receive only plain data types back. If business objects are used by the thread pool, make sure that these are either brand new ones (that haven’t been data bound yet), or are clones of the originals (to avoid concurrent access)
    2. Do the work and obtain a result: Execute the async operation on a background thread. The background thread code will own the ‘safe’ objects given to it by the GUI; it won’t have any interaction with the rest of the application.
    3. Unpack the result in the GUI: When the async operation is finished, it triggers an ‘I am complete’ event on the GUI thread. In response, the GUI thread can unpackage any results from the background operation and merge them back into the main business objects, safe in the knowledge that it won’t be dealing with concurrent access.

    I can recommend the System.Threading.Tasks.Task class as an abstraction around most of the above steps. It’s new in .NET 4.0, but it’s also available as a separate download for .NET 3.5 apps.

    Steps (1) and (2) are what the Task class does without any customisation. You can achieve (3) by spawning a separate Task from inside the background thread and specifying TaskScheduler.FromCurrentSynchronizationContext as a scheduler. (You’ll need to call FromCurrentSynchronizationContext from the GUI thread, in step (1), not from the background thread.)

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

Sidebar

Related Questions

Example: public abstract class BaseControler : Controller { public IUnitOfWork UnitOfWork { get; set;
i got an object with contents of html markup in it, for example: string
Example of strings to search: name = 'bob' person=mary init= 'tim', first =sarah, ,name=o'donnel
Example of WordPress default CSS class output: <li id=menu-item-55 class=menu-item menu-item-type-post_type menu-item-object-page menu-item-55> <li
Example: public class JFrameTest { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want
Example: an Employee table with an optional DateOfBirth field can be normalized into two
Example CSS #wrap{margin:20px} Code prettify wraps the whole line in .com <span class=com>#wrap{margin:20px}</span> Somebody
example: NSString *day = [[NSString stringWithFormat:@السبت];and i think the representation of this string in
Example input string: (F1 (F2 X (Y) Z) (F3 A B) What i want

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.