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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:18:31+00:00 2026-05-17T21:18:31+00:00

An stock data download class has a BarList to which it either adds new

  • 0

An stock data download class has a BarList to which it either adds new bars or updates and replaces the last bar when the last bar changes realtime. Whenever this download class adds a new bar to the BarList class or changes its last bar, it also calls its NotifyOnBarsAdded or NotifyOnBarChanges. I’m trying to get the notify methods to raise events so that the Canvas class which handles these events can redraw the last bar or entire chart depending on which notify method is called. The problem is that when the NotifyOnBarsAdded class is called i get a NullReferenceException as try to raise the event. I am raising the event like this: NotifyBarAdded(this, EventArgs.Empty). Is this incorrect? Here’s the code:

public class BarList : List< Bar >
{
    private int historyHandle;
    public event EventHandler NotifyBarChanged;
    public event EventHandler NotifyBarAdded;

    public BarList(int historyHandle)
    {
        this.historyHandle = historyHandle;
    }

    public BarList()
    {
        // TODO: Complete member initialization
    }

    public void NotifyOnBarChange()
    {
        NotifyBarChanged(this,EventArgs.Empty);
    }

    public void NotifyOnBarsAdded()
    {
         NotifyBarAdded(this, EventArgs.Empty);
    }

    public long handle { get; set; }


}
  • 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-17T21:18:32+00:00Added an answer on May 17, 2026 at 9:18 pm

    What you’re doing is correct, except you have to take into account that there could be no event handlers attached, which will give you a NullReferenceException. You either have to insert a null guard before calling or initialize the events with an empty delegate like this.

    Checking for null:

    var local = NotifyBarAdded;
    if(local != null) local(this, EventArgs.Empty);
    

    Initializing with an empty delegate will allow you to keep the calls you already have (i.e. no need to check for null).

    public event EventHandler NotifyBarAdded = delegate {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to download share data from a stock exchange using python. The problem
I am trying to extract data that corresponds to a stock that is present
I have a stack which contains some integer data. I want to find out
I have a program that downloads basic historical stock data from yahoo and puts
I have a class, say, CDownloader, that reads some XML data and provides access
i download many html store in os,now get their content ,and extract data what
I wrote a python script which I am using to download a large number
I'm using using AsyncTask to download data over internet and I have a little
I have a data frame with stock data (date, symbol, high, low, open, close,
I'm trying to create a PHP script that graphs some historical stock data. I

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.