'-------------------------------------------------
' Searching, Sorting, and Multitasking Comparisons
'
' Written By Jeffrey B. Firestone
' Jeffrey B. Firestone Company
' jfirestone@jbfc.com
'
' May 29, 2004
'
' You may redistribute this control in binary and modified binary form as you please. You may
' use this control in commercial applications without need for external credit royalty free.
'
' However, you are restricted from releasing the source code in any modified fashion
' whatsoever.
'
' I MAKE NO PROMISES OR WARRANTIES ON THIS CODE/CONTROL. IF ANY DAMAGE OR PROBLEMS HAPPEN FROM ITS USE
' THEN YOU ARE RESPONSIBLE.
Option Strict On
Imports System.Xml
Imports System.Threading
Friend Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
InitializeResultsDataSet()
'Add any initialization after the InitializeComponent() call
InitializeGList()
Me.txtDataSize.Text = "10000"
Me.txtScanRepeat.Text = "10"
Me.txtFindRepeat.Text = "1000"
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not m_Thread Is Nothing Then
For iThread As Integer = 0 To UBound(m_Thread)
If Not (m_Thread(iThread) Is Nothing) Then
m_Thread(iThread).Abort()
End If
m_Thread(iThread) = Nothing
Next
m_Thread = Nothing
End If
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItemExit As System.Windows.Forms.MenuItem
Friend WithEvents MenuItemCancel As System.Windows.Forms.MenuItem
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtDataSize As System.Windows.Forms.TextBox
Friend WithEvents lbl2 As System.Windows.Forms.Label
Friend WithEvents txtFindRepeat As System.Windows.Forms.TextBox
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents MenuItemShowData As System.Windows.Forms.MenuItem
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtScanRepeat As System.Windows.Forms.TextBox
Friend WithEvents rbNone As System.Windows.Forms.RadioButton
Friend WithEvents rbDoEvents As System.Windows.Forms.RadioButton
Friend WithEvents grpMultiTasking As System.Windows.Forms.GroupBox
Friend WithEvents rbMultiThreading As System.Windows.Forms.RadioButton
Friend WithEvents glistResults As GlacialComponents.Controls.GlacialList
Friend WithEvents cbThreadPriority As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))
Dim GlColumn1 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn2 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn3 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn4 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn5 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn6 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Dim GlColumn7 As GlacialComponents.Controls.GLColumn = New GlacialComponents.Controls.GLColumn
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItemExit = New System.Windows.Forms.MenuItem
Me.MenuItemShowData = New System.Windows.Forms.MenuItem
Me.MenuItemCancel = New System.Windows.Forms.MenuItem
Me.txtDataSize = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.lbl2 = New System.Windows.Forms.Label
Me.txtFindRepeat = New System.Windows.Forms.TextBox
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.txtScanRepeat = New System.Windows.Forms.TextBox
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.Label2 = New System.Windows.Forms.Label
Me.grpMultiTasking = New System.Windows.Forms.GroupBox
Me.cbThreadPriority = New System.Windows.Forms.ComboBox
Me.rbMultiThreading = New System.Windows.Forms.RadioButton
Me.rbDoEvents = New System.Windows.Forms.RadioButton
Me.rbNone = New System.Windows.Forms.RadioButton
Me.glistResults = New GlacialComponents.Controls.GlacialList
Me.grpMultiTasking.SuspendLayout()
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItemShowData, Me.MenuItemCancel})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItemExit})
Me.MenuItem1.Text = "F&ile"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "&Open"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.Text = "&Save"
'
'MenuItem4
'
Me.MenuItem4.Index = 2
Me.MenuItem4.Text = "Save &As"
'
'MenuItem5
'
Me.MenuItem5.Index = 3
Me.MenuItem5.Text = "-"
'
'MenuItemExit
'
Me.MenuItemExit.Index = 4
Me.MenuItemExit.Text = "E&xit"
'
'MenuItemShowData
'
Me.MenuItemShowData.Index = 1
Me.MenuItemShowData.Text = "Show Data"
'
'MenuItemCancel
'
Me.MenuItemCancel.Index = 2
Me.MenuItemCancel.Text = "Cancel"
'
'txtDataSize
'
Me.txtDataSize.Location = New System.Drawing.Point(512, 24)
Me.txtDataSize.Name = "txtDataSize"
Me.txtDataSize.Size = New System.Drawing.Size(56, 20)
Me.txtDataSize.TabIndex = 2
Me.txtDataSize.Text = ""
Me.ToolTip1.SetToolTip(Me.txtDataSize, "Number of Data Records")
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(456, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Records:"
'
'lbl2
'
Me.lbl2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.lbl2.Location = New System.Drawing.Point(744, 24)
Me.lbl2.Name = "lbl2"
Me.lbl2.Size = New System.Drawing.Size(96, 16)
Me.lbl2.TabIndex = 5
Me.lbl2.Text = "Find Repetitions:"
Me.lbl2.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'txtFindRepeat
'
Me.txtFindRepeat.Location = New System.Drawing.Point(848, 24)
Me.txtFindRepeat.Name = "txtFindRepeat"
Me.txtFindRepeat.Size = New System.Drawing.Size(55, 20)
Me.txtFindRepeat.TabIndex = 4
Me.txtFindRepeat.Text = ""
Me.ToolTip1.SetToolTip(Me.txtFindRepeat, "Number of Time to Repeat the Find Actions")
'
'txtScanRepeat
'
Me.txtScanRepeat.Location = New System.Drawing.Point(680, 24)
Me.txtScanRepeat.Name = "txtScanRepeat"
Me.txtScanRepeat.Size = New System.Drawing.Size(55, 20)
Me.txtScanRepeat.TabIndex = 3
Me.txtScanRepeat.Text = ""
Me.ToolTip1.SetToolTip(Me.txtScanRepeat, "Number of Time to Repeat the Find Actions")
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'Label2
'
Me.Label2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Label2.Location = New System.Drawing.Point(568, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(104, 16)
Me.Label2.TabIndex = 8
Me.Label2.Text = "Scan Repetitions:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'grpMultiTasking
'
Me.grpMultiTasking.Controls.Add(Me.cbThreadPriority)
Me.grpMultiTasking.Controls.Add(Me.rbMultiThreading)
Me.grpMultiTasking.Controls.Add(Me.rbDoEvents)
Me.grpMultiTasking.Controls.Add(Me.rbNone)
Me.grpMultiTasking.Location = New System.Drawing.Point(8, 8)
Me.grpMultiTasking.Name = "grpMultiTasking"
Me.grpMultiTasking.Size = New System.Drawing.Size(384, 45)
Me.grpMultiTasking.TabIndex = 9
Me.grpMultiTasking.TabStop = False
Me.grpMultiTasking.Text = "Multitasking"
'
'cbThreadPriority
'
Me.cbThreadPriority.Items.AddRange(New Object() {"Highest Priority", "Above Normal Priority", "Normal Priority", "Below Normal Priority", "Lowest Priority"})
Me.cbThreadPriority.Location = New System.Drawing.Point(240, 16)
Me.cbThreadPriority.Name = "cbThreadPriority"
Me.cbThreadPriority.Size = New System.Drawing.Size(136, 21)
Me.cbThreadPriority.TabIndex = 3
Me.cbThreadPriority.Text = "Normal Priority"
Me.ToolTip1.SetToolTip(Me.cbThreadPriority, "Set the Background Thread Priority")
'
'rbMultiThreading
'
Me.rbMultiThreading.Checked = True
Me.rbMultiThreading.Location = New System.Drawing.Point(171, 16)
Me.rbMultiThreading.Name = "rbMultiThreading"
Me.rbMultiThreading.Size = New System.Drawing.Size(69, 24)
Me.rbMultiThreading.TabIndex = 2
Me.rbMultiThreading.TabStop = True
Me.rbMultiThreading.Text = "Threads"
Me.ToolTip1.SetToolTip(Me.rbMultiThreading, "Use thread(s) from processing")
'
'rbDoEvents
'
Me.rbDoEvents.Location = New System.Drawing.Point(84, 16)
Me.rbDoEvents.Name = "rbDoEvents"
Me.rbDoEvents.Size = New System.Drawing.Size(80, 24)
Me.rbDoEvents.TabIndex = 1
Me.rbDoEvents.Text = "DoEvents()"
Me.ToolTip1.SetToolTip(Me.rbDoEvents, "Use the DoEvents() function to handle multitasking")
'
'rbNone
'
Me.rbNone.Location = New System.Drawing.Point(8, 16)
Me.rbNone.Name = "rbNone"
Me.rbNone.Size = New System.Drawing.Size(80, 24)
Me.rbNone.TabIndex = 0
Me.rbNone.Text = "Disabled"
Me.ToolTip1.SetToolTip(Me.rbNone, "No multitasking")
'
'glistResults
'
Me.glistResults.AlternateBackground = System.Drawing.Color.White
Me.glistResults.AlternatingColors = True
Me.glistResults.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.glistResults.BackColor = System.Drawing.SystemColors.ControlLightLight
GlColumn1.Name = "Method"
GlColumn1.Text = "Method"
GlColumn1.Width = 275
GlColumn2.Name = "Create"
GlColumn2.Text = "Create"
GlColumn2.Width = 75
GlColumn3.Name = "DatasetScan"
GlColumn3.Text = "Dataset Scan"
GlColumn3.Width = 105
GlColumn4.Name = "Find_1_Key_Field"
GlColumn4.Text = "Find 1 Key Field"
GlColumn4.Width = 125
GlColumn5.Name = "FindAllNon-KeyValues"
GlColumn5.Text = "Find All Non-Key Values"
GlColumn5.Width = 165
GlColumn6.Name = "Find_n_Fields"
GlColumn6.Text = "Find n Fields"
GlColumn6.Width = 120
GlColumn7.Name = "Sort"
GlColumn7.Text = "Sort"
GlColumn7.Width = 90
Me.glistResults.Columns.AddRange(New GlacialComponents.Controls.GLColumn() {GlColumn1, GlColumn2, GlColumn3, GlColumn4, GlColumn5, GlColumn6, GlColumn7})
Me.glistResults.ControlStyle = GlacialComponents.Controls.GLControlStyles.XP
Me.glistResults.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.glistResults.FullRowSelect = False
Me.glistResults.HeaderHeight = 22
Me.glistResults.HotColumnTracking = True
Me.glistResults.HotItemTracking = True
Me.glistResults.HotTrackingColor = System.Drawing.Color.LightGray
Me.glistResults.HoverEvents = False
Me.glistResults.ImageList = Me.ImageList1
Me.glistResults.ItemHeight = 22
Me.glistResults.Location = New System.Drawing.Point(0, 56)
Me.glistResults.MultiSelect = True
Me.glistResults.Name = "glistResults"
Me.glistResults.SelectedTextColor = System.Drawing.Color.Black
Me.glistResults.SelectionColor = System.Drawing.Color.White
Me.glistResults.Size = New System.Drawing.Size(960, 352)
Me.glistResults.TabIndex = 10
Me.glistResults.Text = "glacialList1"
Me.ToolTip1.SetToolTip(Me.glistResults, "Click on a cell to begin processing")
Me.glistResults.UnfocusedSelectionColor = System.Drawing.SystemColors.Highlight
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(960, 409)
Me.Controls.Add(Me.glistResults)
Me.Controls.Add(Me.grpMultiTasking)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtScanRepeat)
Me.Controls.Add(Me.txtFindRepeat)
Me.Controls.Add(Me.txtDataSize)
Me.Controls.Add(Me.lbl2)
Me.Controls.Add(Me.Label1)
Me.Menu = Me.MainMenu1
Me.Name = "frmMain"
Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show
Me.Text = "Seach Sort Method Comparison"
Me.grpMultiTasking.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Public Structure ListViewCellStructure
Dim RowNumber As Integer
Dim ColumnNumber As Integer
Dim Value As String
End Structure
Private m_fCancel As Boolean = False
Public m_TestData As TestData
Private m_Thread(0) As System.Threading.Thread
Private m_DataGridCell As ListViewCellStructure
#Region "Properties"
Public ReadOnly Property Data_Size() As Integer
Get
Data_Size = CInt(Me.txtDataSize.Text)
End Get
End Property
Public ReadOnly Property Scan_Repeat() As Integer
Get
Scan_Repeat = CInt(Me.txtScanRepeat.Text)
End Get
End Property
Public ReadOnly Property Find_Repeat() As Integer
Get
Find_Repeat = CInt(Me.txtFindRepeat.Text)
End Get
End Property
Public Property fCancel() As Boolean
Get
fCancel = m_fCancel
End Get
Set(ByVal Value As Boolean)
m_fCancel = Value
End Set
End Property
Public ReadOnly Property TestData() As TestData
Get
TestData = m_TestData
End Get
End Property
#End Region
#Region "Main Section"
Private Function AddNewRow(ByVal strField As String) As Boolean
#If 0 Then
' Populate the recordset
With Me.dsResults.Results
Dim dr As DataRow = .NewRow()
For Each dc As DataColumn In .Columns
dc.ReadOnly = True
If dc.DataType.Name = "Single" Then
dr.Item(dc) = 0
End If
Next dc
dr.Item("Method") = strField
.Rows.Add(dr)
End With
#End If
Me.glistResults.Items.Add(strField)
End Function
Private Function InitializeResultsDataSet() As Boolean
AddNewRow("ADO Detached Recordset")
AddNewRow("ADO Detached Recordset (Indexed)")
AddNewRow("ADO.NET DataTable")
AddNewRow("ADO.NET DataView")
AddNewRow("Array(X) of Structures")
AddNewRow("Array(X,3) of Objects")
AddNewRow("Collection")
AddNewRow("Array List Collection")
AddNewRow("Sorted List Collection")
AddNewRow("Hashtable Collection")
AddNewRow("Queue Collection")
End Function
Private Function InitializeGList() As Boolean
' Convert the field names such as "Last_Name" to captions like "Last Name"
For Each c As GlacialComponents.Controls.GLColumn In Me.glistResults.Columns
c.Text.Replace("_", " ")
Next
'For Each dr As DataRow In Me.dsResults.Results
'Me.glistResults.Items.Add(dr.Item(0).ToString())
'Next
End Function
Private Sub HandleClick_Startup(ByVal oCell As ListViewCellStructure)
' the proc is called only through the delegate, not directly, since access to the
' members of the control should only be access on its creator's thread, unless using
' the delegate method
If Me.rbNone.Checked Or (oCell.ColumnNumber = 0) Then
Me.Cursor = Cursors.WaitCursor
Me.glistResults.Cursor = Cursors.WaitCursor
End If
If oCell.ColumnNumber > 0 Then
Me.glistResults.Items(oCell.RowNumber).SubItems(oCell.ColumnNumber).Text = "Working..."
End If
End Sub
Private Sub HandleClick_Finish(ByVal oCell As ListViewCellStructure)
' the proc is called only through the delegate, not directly, since access to the
' members of the control should only be access on its creator's thread, unless using
' the delegate method
If oCell.ColumnNumber > 0 Then
'Dim dr As DataRow = dsResults.Results.Rows(oCell.RowNumber)
'Me.dsResults.Results.Columns(oCell.ColumnNumber).ReadOnly = False
'dr.BeginEdit()
'dr(oCell.ColumnNumber) = oCell.Value
'dr.EndEdit()
'Me.dsResults.Results.Columns(oCell.ColumnNumber).ReadOnly = True
Me.glistResults.Items(oCell.RowNumber).SubItems(oCell.ColumnNumber).Text = oCell.Value
End If
If Me.rbNone.Checked Or (oCell.ColumnNumber = 0) Then
Me.glistResults.Cursor = Cursors.Default
Me.Cursor = Cursors.Default
End If
End Sub
Private Delegate Sub HandleClick_Startup_Handler(ByVal oCell As ListViewCellStructure)
Private Delegate Sub HandleClick_Finish_Handler(ByVal oCell As ListViewCellStructure)
Private Sub HandleClick()
' Invoke the processing routine associated with the current ListView cell
Dim oCell As New ListViewCellStructure
With oCell
.RowNumber = m_DataGridCell.RowNumber
.ColumnNumber = m_DataGridCell.ColumnNumber
End With
If Me.rbMultiThreading.Checked Then
Dim oInvoker As HandleClick_Startup_Handler
' Assign address of actual proc to the delegate
oInvoker = New HandleClick_Startup_Handler(AddressOf HandleClick_Startup)
' Invoke the method through the delegate
Me.Invoke(oInvoker, New Object() {oCell})
Else
HandleClick_Startup(oCell)
End If
Dim strResults As String = ""
Dim sDescripton As String = Me.glistResults.Items(oCell.RowNumber).SubItems(0).Text()
Select Case sDescripton
Case "ADO Detached Recordset"
If True Then
Static oADO As ADO
If oADO Is Nothing Then oADO = New ADO
With oADO
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
End If
Case "ADO Detached Recordset (Indexed)"
If True Then
Static oADO_Indexed As ADO_Indexed
If oADO_Indexed Is Nothing Then oADO_Indexed = New ADO_Indexed
With oADO_Indexed
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
End If
Case "ADO.NET DataTable"
Static oADOdotNET_DataTable As ADOdotNET_DataTable
If oADOdotNET_DataTable Is Nothing Then oADOdotNET_DataTable = New ADOdotNET_DataTable
With oADOdotNET_DataTable
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "ADO.NET DataView"
Static oADOdotNET_DataView As ADOdotNET_DataView
If oADOdotNET_DataView Is Nothing Then oADOdotNET_DataView = New ADOdotNET_DataView
With oADOdotNET_DataView
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Array(X) of Structures"
Static oDataArray As Array_Structure
If oDataArray Is Nothing Then oDataArray = New Array_Structure
With oDataArray
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Array(X,3) of Objects"
Static oObjectArray As Array_Object
If oObjectArray Is Nothing Then oObjectArray = New Array_Object
With oObjectArray
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Collection"
Static oCollection As CollectionData
If oCollection Is Nothing Then oCollection = New CollectionData
With oCollection
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Array List Collection"
Static oArrayListCollection As ArrayListCollection
If oArrayListCollection Is Nothing Then oArrayListCollection = New ArrayListCollection
With oArrayListCollection
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Sorted List Collection"
Static oSortedListCollection As SortedListCollection
If oSortedListCollection Is Nothing Then oSortedListCollection = New SortedListCollection
With oSortedListCollection
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Hashtable Collection"
Static oHashtableCollection As HashtableCollection
If oHashtableCollection Is Nothing Then oHashtableCollection = New HashtableCollection
With oHashtableCollection
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case "Queue Collection"
Static oQueueCollection As QueueCollection
If oQueueCollection Is Nothing Then oQueueCollection = New QueueCollection
With oQueueCollection
.frmMain = m_TestData.frmMain
If Not .IsRunning Then strResults = .RunProc(oCell.ColumnNumber, oCell.RowNumber)
End With
Case Else
Beep()
MsgBox("Invalid Choice")
End Select
If (strResults > "") Or (oCell.ColumnNumber = 0) Then
oCell.Value = strResults
' There is a bug in version 1.4 and earlier of the GlacialView controls that we must work around
Try
Me.glistResults.Items(oCell.RowNumber).SubItems(oCell.ColumnNumber).Control = Nothing
Catch
End Try
If rbMultiThreading.Checked Then
Dim oInvoker As HandleClick_Finish_Handler
' Assign address of actual proc to the delegate
oInvoker = New HandleClick_Finish_Handler(AddressOf HandleClick_Finish)
' Invoke the method through the delegate
Me.Invoke(oInvoker, New Object() {oCell})
Else
HandleClick_Finish(oCell)
End If
End If
oCell = Nothing
End Sub
Private Function GetThreadPriority() As ThreadPriority
' Returns the ThreadPriority value for the Thread Priority combobox
Dim iPriority As ThreadPriority = ThreadPriority.Normal
Select Case Me.cbThreadPriority.Text
Case "Highest Priority" : iPriority = ThreadPriority.Highest
Case "Above Normal Priority" : iPriority = ThreadPriority.AboveNormal
Case "Normal Priority" : iPriority = ThreadPriority.Normal
Case "Below Normal Priority" : iPriority = ThreadPriority.BelowNormal
Case "Lowest Priority" : iPriority = ThreadPriority.Lowest
Case Else : iPriority = ThreadPriority.Normal
End Select
Return iPriority
End Function
Private Sub StartThread(ByVal iRowNumber As Integer, ByVal iColumnNumber As Integer)
' Start running the thread associated with the current ListView cell
Static fRunning As Boolean = False
If Me.rbNone.Checked Then
' Don't permit this to be executed more than once at a time
If fRunning Then Exit Sub
End If
fRunning = True
m_fCancel = False
With m_DataGridCell
.RowNumber = iRowNumber
.ColumnNumber = iColumnNumber
End With
' Populate (or re-populate) the m_TestData() object if needed
If m_TestData Is Nothing Then m_TestData = New TestData : m_TestData.frmMain = Me
With m_TestData
If .DataSize <> Data_Size Then
Me.Cursor = Cursors.WaitCursor
Me.glistResults.Cursor = Cursors.WaitCursor
.Create()
Me.glistResults.Cursor = Cursors.Default
Me.Cursor = Cursors.Default
End If
End With
Dim iThread As Integer = m_DataGridCell.RowNumber
If (Me.rbMultiThreading.Checked = True) And (m_DataGridCell.ColumnNumber > 0) Then
If (UBound(m_Thread) < iThread) Then
ReDim Preserve m_Thread(iThread)
End If
If m_Thread(iThread) Is Nothing Then
m_Thread(iThread) = New System.Threading.Thread(AddressOf HandleClick)
m_Thread(iThread).Priority = GetThreadPriority()
m_Thread(iThread).Start()
Else
If m_Thread(iThread).IsAlive = False Then
m_Thread(iThread) = Nothing
m_Thread(iThread) = New System.Threading.Thread(AddressOf HandleClick)
m_Thread(iThread).Priority = GetThreadPriority()
m_Thread(iThread).Start()
End If
End If
Else
HandleClick()
End If
If (Me.rbMultiThreading.Checked = True) And (m_DataGridCell.ColumnNumber > 0) Then
' If the cancel flag is set then check to see if it can be released
If m_fCancel Then
Dim fCancel As Boolean = False
' Check for any running threads, if so, then keep the cancel flag set
For Each thread As System.Threading.Thread In m_Thread
If Not thread Is Nothing Then
If thread.IsAlive Then
fCancel = True
End If
End If
Next
m_fCancel = fCancel
End If
Else
m_fCancel = False
End If
fRunning = False
End Sub
Private Sub cbThreadPriority_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbThreadPriority.SelectedIndexChanged
' Set the priority of all running threads
If Not m_Thread Is Nothing Then
Dim iPriority As ThreadPriority = GetThreadPriority()
For iThread As Integer = 0 To UBound(m_Thread)
If Not (m_Thread(iThread) Is Nothing) Then
If m_Thread(iThread).ThreadState = ThreadState.Running Then
m_Thread(iThread).Priority = GetThreadPriority()
End If
End If
Next
End If
End Sub
#Region "ListView Events"
Private Sub glistResults_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles glistResults.MouseUp
' Start processing the routine associated with the ListView cell the user clicked
If Me.glistResults.HotItemIndex >= 0 Then
Dim iColumnNumber As Integer = 0
Dim iRowNumber As Integer
SyncLock Me
iRowNumber = Me.glistResults.HotItemIndex
End SyncLock
Dim x As Integer = 0
For Each col As GlacialComponents.Controls.GLColumn In Me.glistResults.Columns
x += col.Width
If e.X < x Then
StartThread(iRowNumber, iColumnNumber)
Exit For
End If
iColumnNumber += 1
Next
End If
End Sub
Public Sub UpdateProgress(ByVal iRow As Integer, ByVal iCol As Integer, ByVal iRecord As Integer)
' Update the progress bar embedded in the given ListView cell
Static pbs(20) As ColorProgressBar.ColorProgressBar
If (pbs(iRow) Is Nothing) OrElse (Me.glistResults.Items(iRow).SubItems(iCol).Control Is Nothing) Then
Dim pb As ColorProgressBar.ColorProgressBar = New ColorProgressBar.ColorProgressBar
pb.Maximum = 100
pb.Step = 10
pb.FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Solid
pb.BarColor = Color.Aquamarine
pb.BorderColor = Color.White
pbs(iRow) = pb
Dim ctl As GlacialComponents.Controls.GLSubItem = Me.glistResults.Items(iRow).SubItems(iCol)
Me.glistResults.Items(iRow).SubItems(iCol).Control = pbs(iRow)
Me.glistResults.Refresh()
pb = Nothing
End If
pbs(iRow).Value = iRecord
If iRecord = 100 Then
pbs(iRow) = Nothing
' There is a bug in version 1.4 and earlier of the GlacialView controls that we must work around
Try
Me.glistResults.Items(iRow).SubItems(iCol).Control = Nothing
Catch
End Try
End If
End Sub
#End Region
#Region "Menu Events"
Private Sub MenuItemResizeGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub MenuItemExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemExit.Click
Me.Close()
End Sub
Private Sub MenuItemCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemCancel.Click
m_fCancel = True
End Sub
Private Sub MenuItemShowData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemShowData.Click
Dim frm As ShowData = New ShowData
With frm.dt.Columns
.Add(New DataColumn("lUnique", GetType(Integer)))
.Add(New DataColumn("sUnique", GetType(String)))
.Add(New DataColumn("lNonUnique", GetType(Integer)))
.Add(New DataColumn("sNonUnique", GetType(String)))
End With
If Not (m_TestData Is Nothing) Then
For l As Integer = 0 To m_TestData.arTestData.GetUpperBound(0)
With m_TestData.arTestData(l)
Dim dr As DataRow
dr = frm.dt.NewRow
dr.BeginEdit()
dr.Item("lUnique") = .lUnique
dr.Item("sUnique") = .sUnique
dr.Item("lNonUnique") = .lNonUnique
dr.Item("sNonUnique") = .sNonUnique
dr.EndEdit()
frm.dt.Rows.Add(dr)
End With
Next
End If
With frm
.dg.DataSource = .dt
.Show()
End With
End Sub
#End Region
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
#End Region
End Class