private void SetCurrentSnapshot(HeapSnapshot snapshot)
        {
            // sanity checks
            if (snapshot == null)
            {
                return;
            }

            // remove current "Current item"
            SnapshotListViewItem currentItem = GetSnapshotItem(SnapshotListViewItemState.Current);

            if (currentItem != null)
            {
                currentItem.State = SnapshotListViewItemState.None;

                currentItem.ImageIndex = -1;
                // Note: the item must be redrawn when the image is reset to -1
                lvSnapshots.RedrawItems(currentItem.Index, currentItem.Index, "force redraw" == null);
            }

            // update the new "current" item
            SnapshotListViewItem item = GetSnapshotItem(snapshot);

            item.State      = SnapshotListViewItemState.Current;
            item.ImageIndex = CurrentImageIndex;

            _current = snapshot;
        }
        private void SetReferenceSnapshot(HeapSnapshot snapshot)
        {
            // sanity checks
            if (snapshot == null)
            {
                return;
            }

            // remove current "reference" item
            SnapshotListViewItem referenceItem = GetSnapshotItem(SnapshotListViewItemState.Reference);

            if (referenceItem != null)
            {
                referenceItem.State = SnapshotListViewItemState.None;

                referenceItem.ImageIndex = -1;
                // Note: the item must be redrawn when the image is reset to -1
                lvSnapshots.RedrawItems(referenceItem.Index, referenceItem.Index, "force redraw" == null);
            }

            // update the new "reference" item
            SnapshotListViewItem item = GetSnapshotItem(snapshot);

            item.State      = SnapshotListViewItemState.Reference;
            item.ImageIndex = ReferenceImageIndex;

            _reference = snapshot;
        }
        private void lvSnapshots_DoubleClick(object sender, EventArgs e)
        {
            if (lvSnapshots.SelectedItems.Count > 0)
            {
                SnapshotListViewItem item = (SnapshotListViewItem)lvSnapshots.SelectedItems[0];

                if (item.State == SnapshotListViewItemState.None)
                {
                    SetCurrentSnapshot((HeapSnapshot)item.Tag);
                    CompareSnapshots();
                }
            }
        }
        private void AddSnapshot(HeapSnapshot snapshot)
        {
            // update the list
            SnapshotListViewItem lvSnapshot = new SnapshotListViewItem();

            lvSnapshot.Tag = snapshot;
            lvSnapshot.SubItems.Add(snapshot.ObjectCount.ToString("#,#"));
            lvSnapshot.SubItems.Add(snapshot.Size.ToString("#,#"));

            lvSnapshots.Items.Add(lvSnapshot);

            // update the chart
            chartCount.Series["Series2"].Points.AddY(snapshot.ObjectCount);
            chartSize.Series["Series1"].Points.AddY(snapshot.Size);
        }
        private void btnSetReference_Click(object sender, EventArgs e)
        {
            if (lvSnapshots.SelectedItems.Count == 0)
            {
                MessageBox.Show("You first have to select a snapshot", "Changing Reference snapshot", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // sanity checks
            SnapshotListViewItem item = (SnapshotListViewItem)lvSnapshots.SelectedItems[0];

            if (item.State == SnapshotListViewItemState.None)
            {
                SetReferenceSnapshot((HeapSnapshot)lvSnapshots.SelectedItems[0].Tag);
                CompareSnapshots();
            }
        }
        private void lvSnapshots_KeyUp(object sender, KeyEventArgs e)
        {
            // only handle the DEL key
            if (e.KeyCode != Keys.Delete)
            {
                return;
            }

            if (lvSnapshots.SelectedItems.Count > 0)
            {
                SnapshotListViewItem item = (SnapshotListViewItem)lvSnapshots.SelectedItems[0];
                if (item.State == SnapshotListViewItemState.None)
                {
                    int index = lvSnapshots.Items.IndexOf(item);
                    lvSnapshots.Items.Remove(item);

                    // update the chart
                    chartCount.Series["Series2"].Points.RemoveAt(index);
                    chartSize.Series["Series1"].Points.RemoveAt(index);
                }
            }
        }