I have a multi-form program each window should be running independent of the other. The problem is that for some reason the second window will not process until the first is finished. I just ran it again and now they are working in reverse order.
A little background so you will understand some things in the code. StatusList is a control that takes a collection of StatusListItems. This is placed on CheckList_frm that just keeps track of progress and other information of the individual forms. query_frm just handles data collection that each main_frm will then process. query_frm_DataReady is an event raised on the query_frm once complete, but handled on the CheckList_frm.
Here is the code that creates the form.
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
A little background so you will understand some things in the code. StatusList is a control that takes a collection of StatusListItems. This is placed on CheckList_frm that just keeps track of progress and other information of the individual forms. query_frm just handles data collection that each main_frm will then process. query_frm_DataReady is an event raised on the query_frm once complete, but handled on the CheckList_frm.
Here is the code that creates the form.
Code:
Private Sub query_frm_DataReady(ByVal Table As DataTable)
If Me.InvokeRequired Then
Me.Invoke(New delStartSessions(AddressOf StartSessions), Table)
Else
StartSessions(Table)
End If
End Sub
Public Delegate Sub delStartSessions(ByVal Table As DataTable)
Public Sub StartSessions(ByVal Table As DataTable)
If qfrm IsNot Nothing Then
If qfrm.Visible = True Then qfrm.Close()
qfrm = Nothing
GC.Collect()
End If
If Table IsNot Nothing Then
If Table.Rows.Count > 0 Then
Dim WindowNumber As Integer = CInt(nud_tss.value + 0.5)
Dim WindowCount As Integer = 0
Dim SplitTable As Integer = Table.Rows.Count / Me.nud_tss.value
Dim MaxCount As Integer = SplitTable
Dim LastCount As Integer = 0
Me.run_tssb.Enabled = False
For count As Integer = 1 To nud_tss.value
Dim newMainFrm As main_frm
Dim formDataRow(MaxCount - 1) As DataRow
Dim rowCount As Integer
newMainFrm = New main_frm
newMainFrm.Name = "main_frm_" & count
newMainFrm.Text = newMainFrm.Name
newMainFrm.ShowInTaskbar = False
For rowCount = 1 To MaxCount
formDataRow(rowCount - 1) = Table.Rows((LastCount + rowCount) - 1)
Next
If count <> nud_tss.value Then
LastCount += rowCount - 1
MaxCount = ((Table.Rows.Count - LastCount) / (nud_tss.value - count))
End If
Dim cWBdata As New StatusListItem
cWBdata.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
cWBdata.AutoSize = True
cWBdata.Text = "main_frm_" & count
cWBdata.EmailStatus = StatusListItem.StatusType.NoEmail
cWBdata.SetStatusChange = StatusListItem.CheckMarkStatus.NotChecked
cWBdata.AutoSize = True
cWBdata.HideStatus = True
cWBdata.ProgressVisible = True
cWBdata.Minimum = 0
cWBdata.Maximum = formDataRow.Length
cWBdata.Value = 0
cWBdata.ListItemProgressBar.TextStyle = clCustomControls.CustomProgressBar.BarTextStyle.ValueOfMax
AddHandler cWBdata.Click, AddressOf ListItem_Click
AddHandler cWBdata.DoublClick, AddressOf ListItemDoubleClick
AddHandler cWBdata.ListItemContextMenuItemClick, AddressOf ListItemContextMenuClick
StatusList.Add(cWBdata)
cWBdata = Nothing
If My.Settings.AutoDock = True Then
Dim AvailableArea As System.Drawing.Rectangle
If My.Settings.SpreadWindows = False Then
AvailableArea = New System.Drawing.Rectangle(Me.Location.X + Me.Width, Me.Location.Y, CurrentScreen.WorkingArea.Width - Me.Width, Me.Height)
Else
Dim DualScreen As New clDualScreen.DualScreen
AvailableArea = DualScreen.TotalScreenArea(Me)
End If
If nud_tss.value > 1 Then
Dim x, y, w, h As Integer
If AvailableArea.Width >= AvailableArea.Height Then
If (count Mod 2) = 0 Then
w = AvailableArea.Width / 2
h = AvailableArea.Height / (WindowNumber / 2)
x = Me.Width + w
y = AvailableArea.Y + ((h * (count / 2)) - h)
Else
Dim t As Integer = (count Mod 1)
w = AvailableArea.Width / 2
h = AvailableArea.Height / (WindowNumber / 2)
x = Me.Width
y = AvailableArea.Y + ((h * ((count + 1) / 2)) - h)
End If
End If
newMainFrm.Bounds = New System.Drawing.Rectangle(x, y, w, h)
Else
newMainFrm.Bounds = My.Settings.IcomsScreenDefaultSize
End If
End If
newMainFrm.ProcessDataRows = formDataRow
newMainFrm.Show()
Next
sMessage("Total Records: " & Table.Rows.Count)
Me.Focus()
End If
End If
End Sub
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!