-1

I have a window with a datagrid and a chart. The data grid has 5 rows of data and the chart graphs the data of the row based on the selected row. Right now it only graphs the first row and doesn't update the graph when I select a different row. This code is in a class called ShellViewModel.cs:

public void EditLoadForecastViewModel()
{
    Shell sh;
    Timer timer = new Timer(500);
    timer.Elapsed += new ElapsedEventHandler((s, e) =>
    {
        if (updateGraph)
        {
            sh.Dispatcher.BeginInvoke(new Action(() => UpdateLoadChart()), null);
            updateGraph = false;
        }
    });
    timer.Start()
}

This function is called in a window called Shell.xaml like this

private void btnResults_Click(object sender, RoutedEventArgs e)
{
    vm.ReadLoadForecastFile(false,false);
    vm.EditLoadForecastViewModel();
}

When the button is pressed i get an error pointing at this line:

sh.Dispatcher.BeginInvoke(new Action(() => UpdateLoadChart()), null);

The error message is

NullReferenceException was unhandled by user code : Object reference not set to an instance of an object

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
Satish
  • 325
  • 1
  • 3
  • 12

1 Answers1

0

Instantiate a new instance of the Shell object sh.

Shell sh = new Shell();
sammarcow
  • 2,736
  • 2
  • 28
  • 56