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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:51:45+00:00 2026-05-26T03:51:45+00:00

How my programs works I have backend with several objects, which have PropetyChanged event.

  • 0

How my programs works

I have backend with several objects, which have PropetyChanged event. When some property is changed, the notification is fired. On the frontend side I have GUI written in WPF, and several properties are binded directly to WPF widgets.

To make GUI responsive, all the computation is done in additional thread.

So, in general, classic WPF app.

Error

public void OnPropertyChanged(string name)
{
  if (PropertyChanged != null)
    PropertyChanged(this, new PropertyChangedEventArgs(name)); // (*)
}

This code sends notifications, however it throws exception at (*) because PropertyChanged is null (yes, just after checking for null).

Question

My guess is it is because of rebinding in WPF — in my code I change the sender, so WPF has to unregister receiver and register it to the new sender. Exception is thrown rarely (I get one exception every ~40000 executions passes, each one is equivalent roughly to one change of the sender) but it does happen.

Now — how to properly lock PropertyChange, so I can check for null AND send the notification as an atomic operation? I don’t want to do this by trial & error, because I could find out side effects in every 1M-th execution.

  • 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-26T03:51:46+00:00Added an answer on May 26, 2026 at 3:51 am

    There is a pattern to solve this problem:

    var evt = PropertyChanged;
    if ( evt != null ) evt( this, new PropertyChangedEventArgs( name ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two begininer programs, both using the 'while' function, one works correctly, and
hi I have disassembled some programs (linux) I wrote to understand better how it
I'm working on learning TDD while writing some small ruby programs. I have the
i have been working on a server and it works with 2 programs i
I have 2 programs, both written in Java. The first launches several instances of
I have been trying to run some java programs from a bash script in
After some time using make to build C++ programs I still don't have a
I have a program that works with a variety of files on both the
I have an OpenGL program that works on all of my computers but one.
I have a popup function in a program that works well, be re-loads the

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.