0

バックグラウンドワーカーが完了すると呼び出されるルーチンがあります。以下のように;

private void BatteryListFetchBackgroundWorkerRunWorkerCompleter(object sender, RunWorkerCompletedEventArgs e)
{
    this.Cursor = Cursors.Default;
    var sortedList = this.currentBatteries.Values.OrderBy(g => g, new BatteryNameComparer()); //breaks here

    this.BatteryBindingSource.DataSource = sortedList;
    if (this.batteryListBox.Items.Count > 0)
    {
        this.batteryListBox.SetSelected(0, true);
    }

    this.viewScheduleButton.Enabled = true;
    this.viewDefaultScheduleButton.Enabled = true;
    this.viewEditScheduleLimits.Enabled = true;
}

壊れている行は次のとおりです。

                this.BatteryBindingSource.DataSource = sortedList;

例外はnull参照例外であり、データソースの設定時に発生します

のコードBatteryNameComparer

 public class BatteryNameComparer : IComparer<Battery>
{
    /// <summary>
    /// Compares DDSMGroup 
    /// </summary>
    /// <param name="a">first value for comparison</param>
    /// <param name="b">second value for comparison</param>
    /// <returns>An integer indicating the compare result</returns>
    public int Compare(Battery a, Battery b)
    {
        int aId = int.Parse(a.DeviceName.Substring(BatteryOverviewControl.BatteryPrefixSubstring.Length));
        int bId = int.Parse(b.DeviceName.Substring(BatteryOverviewControl.BatteryPrefixSubstring.Length));

        return aId.CompareTo(bId);
    }
}
4

1 に答える 1