Source

SOSNet / SOS.Net / FormMain.cs

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using SOS.Net.Core;
using SOS.Net.Core.Cdb;

namespace SOS.Net
{
    public partial class FormMain : Form
    {
        private SosController controller = new SosController();

        private InstanceInfoDetails currentInstance;

        public FormMain()
        {
            InitializeComponent();
            controller.OnCdbOuput += new EventHandler<CdbEventArgs>(controller_OnCdbOuput);
        }

        void controller_OnCdbOuput(object sender, CdbEventArgs e)
        {
            this.textBoxCdbOuput.AppendText(e.Intput);
            this.textBoxCdbOuput.AppendText(Environment.NewLine);
            this.textBoxCdbOuput.AppendText(e.Output);
            this.textBoxCdbOuput.AppendText(Environment.NewLine);
            this.MoveOutputToEnd();
        }

        private void MoveOutputToEnd()
        {
            this.textBoxCdbOuput.SelectionStart = this.textBoxCdbOuput.Text.Length;
            this.textBoxCdbOuput.SelectionLength = 0;
            this.textBoxCdbOuput.ScrollToCaret();
        }

        private void toolStripButtonRefreshProcesses_Click(object sender, EventArgs e)
        {
            this.RefreshProcesses();
        }

        private void RefreshProcesses()
        {
            this.tabControlMain.SelectTab(this.tabPageProcesses);

            var result = this.controller.RefreshProcesses();
            if(!string.IsNullOrEmpty(this.textBoxSearchProcesses.Text))
                result = this.controller.FilterProcesses(this.textBoxSearchProcesses.Text);


            updateListViewItemsWithNewItems(result, this.listViewProcesses);
        }

        private void updateListViewItemsWithNewItems(ListViewItem[] result, ListView listViewToRefreshWithNewItems)
        {
            listViewToRefreshWithNewItems.BeginUpdate();
            listViewToRefreshWithNewItems.Items.Clear();
            listViewToRefreshWithNewItems.Items.AddRange(result);
            performSort(listViewToRefreshWithNewItems);
            listViewToRefreshWithNewItems.EndUpdate();
        }

        private void textBoxSearchProcesses_TextChanged(object sender, EventArgs e)
        {
            this.timerFilter.Enabled = false;
            this.timerFilter.Enabled = true;
        }

        private void timerFilter_Tick(object sender, EventArgs e)
        {
            this.timerFilter.Enabled = false;
            this.listViewProcesses.BeginUpdate();
            this.listViewProcesses.Items.Clear();
            this.listViewProcesses.Items.AddRange(this.controller.FilterProcesses(this.textBoxSearchProcesses.Text));
            this.listViewProcesses.EndUpdate();            
        }

        private void toolStripButtonAttach_Click(object sender, EventArgs e)
        {
            this.AttachSelectedProcess();
        }

        private void AttachSelectedProcess()
        {
            if(this.listViewProcesses.SelectedIndices != null && this.listViewProcesses.SelectedIndices.Count > 0)
            {
                var selected = this.listViewProcesses.Items[this.listViewProcesses.SelectedIndices[0]];
                this.controller.AttachToProcess(selected.SubItems[0].Text);

                this.toolStripButtonAttach.Enabled = false;
                this.toolStripButtonDetach.Enabled = true;
                this.appDomainsToolStripMenuItem.Enabled = true;
                this.assembliesToolStripMenuItem.Enabled = true;
                this.typesToolStripMenuItem.Enabled = true;
            }
            
            this.RefreshAppDomains();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            var settings = this.controller.LoadSettings();
            this.textBoxCBDPath.Text = settings.CdbPath;
            this.textBoxSosexPath.Text = settings.SosexPath;
        }

        private void toolStripButtonSaveSettings_Click(object sender, EventArgs e)
        {
            var settings = new CdbSettings
                           {
                               CdbPath = this.textBoxCBDPath.Text,
                               SosexPath = this.textBoxSosexPath.Text
                           };
            this.controller.SaveSettings(settings);
        }

        private void listViewProcesses_DoubleClick(object sender, EventArgs e)
        {
            this.AttachSelectedProcess();
        }

        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.controller.Dispose();
        }

        private void toolStripButtonDetach_Click(object sender, EventArgs e)
        {
            this.controller.Detach();

            this.toolStripButtonDetach.Enabled = false;
            this.appDomainsToolStripMenuItem.Enabled = false;
            this.assembliesToolStripMenuItem.Enabled = false;
            this.typesToolStripMenuItem.Enabled = false;
            this.toolStripButtonAttach.Enabled = listViewProcesses.SelectedIndices.Count == 1;
        }

        private void textBoxCdbInput_KeyDown(object sender, KeyEventArgs e)
        {            
            if(e.KeyValue == 13)
            {
                // RETURN
                this.controller.ExecuteCommand(this.textBoxCdbInput.Text);
                this.textBoxCdbInput.Text = string.Empty;
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
            else if(e.KeyValue == 38)
            {
                // UP
                this.textBoxCdbInput.Text = this.controller.GetNextCommand();
                this.textBoxCdbInput.SelectAll();
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
            else if(e.KeyValue == 40)
            {
                // DOWN
                this.textBoxCdbInput.Text = this.controller.GetPreviousCommand();
                this.textBoxCdbInput.SelectAll();
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }

        private void toolStripButtonRefreshAppDomains_Click(object sender, EventArgs e)
        {
            this.RefreshAppDomains();
        }

        private void RefreshAppDomains()
        {
            System.Diagnostics.Debug.Assert(controller.Attached,"can't refresh appdomains if not attached"); // occurs when clicking refresh on the app domain tab without attaching a process up front
            this.tabControlMain.SelectTab(this.tabPageAppDomain);

            this.listViewAppDomains.BeginUpdate();
            this.listViewAppDomains.Items.Clear();
            this.listViewAppDomains.Items.AddRange(this.controller.GetAllAppDomains());
            this.listViewAppDomains.EndUpdate();
        }

        private void listViewAppDomains_DoubleClick(object sender, EventArgs e)
        {
            this.RefreshSelectedAppDomainsAssemblies();
        }

        private void RefreshAssemblies()
        {
            this.tabControlMain.SelectTab(this.tabPageAssemblies);

            this.listViewAssemblies.BeginUpdate();
            this.listViewAssemblies.Items.Clear();
            this.listViewAssemblies.Items.AddRange(this.controller.GetAssemblies());
            this.listViewAssemblies.EndUpdate();
        }

        private void RefreshSelectedAppDomainsAssemblies()
        {
            this.tabControlMain.SelectTab(this.tabPageAssemblies);

            if (this.listViewAppDomains.SelectedIndices != null && this.listViewAppDomains.SelectedIndices.Count > 0)
            {
                var selected = this.listViewAppDomains.Items[this.listViewAppDomains.SelectedIndices[0]];
                
                this.listViewAssemblies.BeginUpdate();
                this.listViewAssemblies.Items.Clear();
                this.listViewAssemblies.Items.AddRange( this.controller.GetAssemblies(selected.SubItems[0].Text));
                this.listViewAssemblies.EndUpdate();
            }
        }

        private void toolStripButtonRefreshAssemblies_Click(object sender, EventArgs e)
        {
            this.RefreshSelectedAppDomainsAssemblies();
        }

        private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(this.tabControlMain.SelectedTab == this.tabPageOutput)
                this.MoveOutputToEnd();
        }

        private void toolStripSplitButtonRefresh_ButtonClick(object sender, EventArgs e)
        {
            if(this.tabControlMain.SelectedTab == this.tabPageProcesses)
                this.RefreshProcesses();
            else if (this.tabControlMain.SelectedTab == this.tabPageAppDomain)
                this.RefreshAppDomains();
            else if (this.tabControlMain.SelectedTab == this.tabPageAssemblies)
                this.RefreshAssemblies();
            else if (this.tabControlMain.SelectedTab == this.tabPageTypes)
                this.RefreshTypes();
            else if (this.tabControlMain.SelectedTab == this.tabPageInstances)
                this.RefreshSelectedTypeInstances();
        }

        private void RefreshSelectedTypeInstances()
        {
            this.tabControlMain.SelectTab(this.tabPageInstances);

            if (this.listViewHeap.SelectedIndices != null && this.listViewHeap.SelectedIndices.Count > 0)
            {
                var selected = this.listViewHeap.Items[this.listViewHeap.SelectedIndices[0]];

                this.listViewInstances.BeginUpdate();
                this.listViewInstances.Items.Clear();
                this.listViewInstances.Items.AddRange(this.controller.GetInstances(selected.SubItems[0].Text));
                this.listViewInstances.EndUpdate();
            }
        }

        private void typesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.RefreshTypes();
        }

        private void RefreshTypes()
        {
            this.tabControlMain.SelectTab(this.tabPageTypes);

            this.listViewHeap.BeginUpdate();
            this.listViewHeap.Items.Clear();
            this.listViewHeap.Items.AddRange(this.controller.GetDumpHeapTypes());
            this.listViewHeap.EndUpdate();

            if(!string.IsNullOrEmpty(this.textBoxTypeSearch.Text))
            {
                this.listViewHeap.BeginUpdate();
                this.listViewHeap.Items.Clear();
                this.listViewHeap.Items.AddRange(this.controller.FilterTypes(this.textBoxTypeSearch.Text));
                this.listViewHeap.EndUpdate();
            }
        }

        private void RefreshSelectedTypeObjectDump()
        {
            this.tabControlMain.SelectTab(this.tabPageInstances);

            this.flowLayoutPanelBreadcrumb.Controls.Clear();

            if (this.listViewInstances.SelectedIndices != null && this.listViewInstances.SelectedIndices.Count > 0)
            {
                var selected = this.listViewInstances.Items[this.listViewInstances.SelectedIndices[0]];

                Button button = this.CreateInstanceButton(selected.SubItems[0].Text);

                this.flowLayoutPanelBreadcrumb.Controls.Add(button);

                this.OnInstanceSelected(button);
            }
        }

        private Button CreateInstanceButton(string address)
        {
            var instanceInfo = this.controller.GetInstanceDumpDetails(address);

            Button button = new Button();
            button.AutoSize = true;
            button.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            button.Text = instanceInfo.Name;
            button.Tag = instanceInfo;
            button.Click += new EventHandler(this.button_Click);
            button.Font = new Font(button.Font, FontStyle.Bold);

            return button;
        }

        private Button CreateInstanceButton(string address, string index)
        {
            var instanceInfo = this.controller.GetInstanceDumpDetails(address, index);

            Button button = new Button();
            button.AutoSize = true;
            button.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            button.Text = instanceInfo.Name;
            button.Tag = instanceInfo;
            button.Click += new EventHandler(this.button_Click);
            button.Font = new Font(button.Font, FontStyle.Bold);

            return button;
        }

        void button_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            OnInstanceSelected(button);           
        }

        private void OnInstanceSelected(Button button)
        {
            foreach (var item in this.flowLayoutPanelBreadcrumb.Controls)
            {
                Button otherButtons = item as Button;
                if (otherButtons != null)
                {
                    otherButtons.Font = new Font(otherButtons.Font, FontStyle.Regular);                    
                }
            }

            button.Font = new Font(button.Font, FontStyle.Bold);
            string address = ((InstanceInfoDetails)button.Tag).Address;
            string index = ((InstanceInfoDetails)button.Tag).Index;
            string type = ((InstanceInfoDetails) button.Tag).Name;

            if (string.IsNullOrEmpty(index))
            {
                this.listViewObjectDump.BeginUpdate();
                this.listViewObjectDump.Items.Clear();
                this.listViewObjectDump.Items.AddRange(this.controller.GetInstanceDump(address));
                this.listViewObjectDump.EndUpdate();

                var instanceInfo = this.controller.GetInstanceDumpDetails(address);
                this.textBoxObjectDumpType.Text = instanceInfo.Name;
                this.textBoxObjectDumpToString.Text = instanceInfo.String;
                this.textBoxObjectDumpSize.Text = instanceInfo.TrueSize;
                this.textBoxObjectDumpAddress.Text = instanceInfo.Address;
            }
            else
            {
                this.listViewObjectDump.BeginUpdate();
                this.listViewObjectDump.Items.Clear();
                this.listViewObjectDump.Items.AddRange(this.controller.GetInstanceDump(address, index));
                this.listViewObjectDump.EndUpdate();

                var instanceInfo = this.controller.GetInstanceDumpDetails(address, index);
                this.textBoxObjectDumpType.Text = instanceInfo.Name;
                this.textBoxObjectDumpToString.Text = instanceInfo.String;
                this.textBoxObjectDumpSize.Text = instanceInfo.TrueSize;
                this.textBoxObjectDumpAddress.Text = instanceInfo.Address;
            }

            if (type.EndsWith("[]") || type.Equals("SZARRAY"))
            {
                // the type is an array, display the collection
                this.splitContainerObjectDumpDetails.Panel2Collapsed = false;
                this.listViewFieldArray.BeginUpdate();
                this.listViewFieldArray.Items.Clear();
                this.listViewFieldArray.Items.AddRange(this.controller.GetArrayInstances(address));
                this.listViewFieldArray.EndUpdate();
            }
            else
            {
                this.splitContainerObjectDumpDetails.Panel2Collapsed = true;
            }

            currentInstance = ((InstanceInfoDetails)button.Tag);
        }

        private void listViewHeap_DoubleClick(object sender, EventArgs e)
        {
            this.RefreshSelectedTypeInstances();
        }

        private void listViewInstances_DoubleClick(object sender, EventArgs e)
        {
            this.RefreshSelectedTypeObjectDump();
        }

        private void timerTypeFilter_Tick(object sender, EventArgs e)
        {
            this.timerTypeFilter.Enabled = false;
            this.listViewHeap.BeginUpdate();
            this.listViewHeap.Items.Clear();
            this.listViewHeap.Items.AddRange(this.controller.FilterTypes(this.textBoxTypeSearch.Text));
            this.listViewHeap.EndUpdate(); 
        }

        private void textBoxTypeSearch_TextChanged(object sender, EventArgs e)
        {
            this.timerTypeFilter.Enabled = false;
            this.timerTypeFilter.Enabled = true;
        }

        private void listViewObjectDump_DoubleClick(object sender, EventArgs e)
        {
            if (this.listViewObjectDump.SelectedIndices != null && this.listViewObjectDump.SelectedIndices.Count > 0)
            {
                var selected = this.listViewObjectDump.Items[this.listViewObjectDump.SelectedIndices[0]];

                var selectedType = selected.SubItems[1].Text;

                var selectedAddress = selected.SubItems[3].Text;

                if (selectedType.EndsWith("[]") || selectedType.Equals("SZARRAY"))
                {
                    // the type is an array, display the collection
                    this.splitContainerObjectDumpDetails.Panel2Collapsed = false;
                    this.listViewFieldArray.BeginUpdate();
                    this.listViewFieldArray.Items.Clear();
                    this.listViewFieldArray.Items.AddRange(this.controller.GetArrayInstances(selectedAddress));
                    this.listViewFieldArray.EndUpdate(); 
                }
                else
                {
                    Button newInstance = CreateInstanceButton(selectedAddress);
                    DisplayInstanceDetails(newInstance);
                }
            }
        }

        private void DisplayInstanceDetails(Button newInstance)
        {            
            if (!string.IsNullOrEmpty(newInstance.Text))
            {
                // search the current object in breadcrumb
                List<Button> items = new List<Button>();
                bool found = false;
                foreach (var item in this.flowLayoutPanelBreadcrumb.Controls)
                {
                    Button button = item as Button;
                    if (button != null)
                    {
                        if (!found)
                        {
                            items.Add(button);

                            string addr = ((InstanceInfoDetails)button.Tag).Address;
                            string index = ((InstanceInfoDetails)button.Tag).Index;
                            if (object.Equals(currentInstance.Address,addr) && object.Equals(currentInstance.Index, index))
                                found = true;
                        }
                    }
                }

                // remove all "after" items
                this.flowLayoutPanelBreadcrumb.Controls.Clear();

                // add new "selected" breadcrumb item                
                items.Add(newInstance);

                this.flowLayoutPanelBreadcrumb.Controls.AddRange(items.ToArray());

                this.OnInstanceSelected(newInstance);

            }
        }

        private void listViewProcesses_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(listViewProcesses.SelectedIndices.Count == 1)
            {
                this.toolStripButtonAttach.Enabled = true && !this.controller.Attached;
            }
            else
            {
                this.toolStripButtonAttach.Enabled = false;
            }
        }

        private void listViewFieldArray_DoubleClick(object sender, EventArgs e)
        {
            if (this.listViewFieldArray.SelectedIndices != null && this.listViewFieldArray.SelectedIndices.Count > 0)
            {
                var selected = this.listViewFieldArray.Items[this.listViewFieldArray.SelectedIndices[0]];

                string address;
                if (textBoxObjectDumpType.Text.EndsWith("[]") || textBoxObjectDumpType.Text.Equals("SZARRAY"))
                {
                    address = this.textBoxObjectDumpAddress.Text;
                }
                else
                {
                    var selectedField = this.listViewObjectDump.Items[this.listViewObjectDump.SelectedIndices[0]];
                    address = selectedField.SubItems[3].Text;
                }                

                this.splitContainerObjectDumpDetails.Panel2Collapsed = true;
                Button newInstance = CreateInstanceButton(address, selected.SubItems[0].Text);
                this.DisplayInstanceDetails(newInstance);
            }
        }

        private void helpOnlineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Help.ShowHelp(this, "http://bitbucket.org/grozeille/sosnet/wiki/Home");
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AboutForm().ShowDialog();
        }

        private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Help.ShowHelp(this, (sender as LinkLabel).Text);
        }

        private void toolStripButtonHelp_ButtonClick(object sender, EventArgs e)
        {
            new AboutForm().ShowDialog();
        }

        private void listView_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            var listview = (ListView)sender;

            // Create an instance of the ColHeader class.
            ColumnHeader clickedCol = (ColumnHeader)listview.Columns[e.Column];

            // Set the ascending property to sort in the opposite order.
            if (clickedCol.Tag == null)
                clickedCol.Tag = false;
            else
            {
                clickedCol.Tag = !((bool)clickedCol.Tag);
            }


            var ascending = (bool)clickedCol.Tag;

            persistSort(listview, e.Column, ascending);
            
            performSort(listview);
        }


            Dictionary<ListView, KeyValuePair<int,bool>> columnSortByListViewMap = new Dictionary<ListView, KeyValuePair<int, bool>>();

        private void persistSort(ListView listViewToPersistSortOrder, int columnIndex, bool isAscending)
        {
            var sortingDetails = new KeyValuePair<int,bool>(columnIndex, isAscending);
                columnSortByListViewMap[listViewToPersistSortOrder] = sortingDetails;
        }

            private void getSort(ListView listViewToRetriveSortInfoFor, out int columnIndex, out bool isAscending)
            {
                if(columnSortByListViewMap.ContainsKey(listViewToRetriveSortInfoFor))
                {
                    var sortingdetails = columnSortByListViewMap[listViewToRetriveSortInfoFor];
                    columnIndex = sortingdetails.Key;
                    isAscending = sortingdetails.Value;
                }
                else
                {
									
                    columnIndex = 0;
                    isAscending = true;
                	var sortingdetails = new KeyValuePair<int, bool>(columnIndex, isAscending);
									columnSortByListViewMap[listViewToRetriveSortInfoFor] = sortingdetails;
                }
            }

        private void performSort(ListView listview/*, ColumnClickEventArgs e, bool ascending*/)
        {
						// Get the number of items in the list.
            int columnIndexToSortOver;
            bool isAscending;
            getSort(listview, out columnIndexToSortOver, out isAscending);
            int numItems = listview.Items.Count;

            // Turn off display while data is repoplulated.
            listview.BeginUpdate();

            // Populate an ArrayList with a SortWrapper of each list item.
            ArrayList SortArray = new ArrayList();
            for (int i = 0; i < numItems; i++)
            {
                SortArray.Add(new SortWrapper(listview.Items[i],columnIndexToSortOver));
            }

            // Sort the elements in the ArrayList using a new instance of the SortComparer
            // class. The parameters are the starting index, the length of the range to sort,
            // and the IComparer implementation to use for comparing elements. Note that
            // the IComparer implementation (SortComparer) requires the sort
            // direction for its constructor; true if ascending, othwise false.
            SortArray.Sort(0, SortArray.Count, new SortWrapper.SortComparer(isAscending));

            // Clear the list, and repopulate with the sorted items.
            listview.Items.Clear();
            for (int i = 0; i < numItems; i++)
                listview.Items.Add(((SortWrapper)SortArray[i]).sortItem);

            // Turn display back on.
            listview.EndUpdate();
        }
    }
}