title: Forms not closing when they should
body: <p>Hey all, i have a problem with trying to get 2 forms to close at different times using a timer on each of the 2 forms.</p>
  
  <p>This is my form layout:</p>
  
  <p>frmMain
  Frm1
  Frm2</p>
  
  <p>Frm1 and Frm2 are identical to each other. FrmMain has 2 buttons on it. One button to call Frm1 and the other to call Frm2.</p>
  
  <p>Frm1 and Frm2 each has a timer. It counts down to 0 and then does a .close(). However, if i pause between clicking the second button they both seem to always disappears at the same time.</p>
  
  <p>I would do something like this...</p>
  
  <p>Click on the first button (showing the Frm1 form)
  wait about 10 secs...
  Click on the second button (showing the Frm2 form)
  they both are shown on screen...
  then they both disappear at the same time.... which shouldn't happen since i clicked the Frm2 box 10 seconds AFTER Frm1... So Frm1 should hide before Frm2 does...but it does not.</p>
  
  <p>Any help to this problem would be great! :)</p>
  
  <p><B> updated with code</b></p>
  
  <pre><code>Public Sub showMessageBox(ByVal typeOfBox As String, ByVal theMessage As String)
      If Form2.theNumOpened &lt;= 6 Then
          Form2.theNumOpened = Form2.theNumOpened + 1 'ADDED
  
          Me.Opacity = 0
          Me.Show()
  
          Select Case Form2.theNumOpened
              Case 1
                  Me.Text = "NBMsg1"
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case 2
                  Me.Text = "NBMsg2"
                  Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg1")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case 3
                  Me.Text = "NBMsg3"
                  Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg2")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg1")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case 4
                  Me.Text = "NBMsg4"
                  Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg3")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg2")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg1")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case 5
                  Me.Text = "NBMsg5"
                  Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg4")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg3")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg2")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg1")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 4) + 25, 0, 0, 1)
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case 6
                  Me.Text = "NBMsg6"
                  Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg5")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg4")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg3")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg2")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 4) + 25, 0, 0, 1)
                  hwnd = FindWindow(vbNullString, "NBMsg1")
                  SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 5) + 30, 0, 0, 1)
                  Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
              Case Else
                  Me.Close()
                  Me.Dispose()
          End Select
  
          isLoading = True
          theType = typeOfBox
          lblSaying.Text = theMessage
  
          If typeOfBox = "OK" Then
              Me.BackColor = Color.FromArgb(192, 255, 192)
          ElseIf typeOfBox = "ERR" Then
              Me.BackColor = Color.FromArgb(255, 192, 192)
          Else
              Me.BackColor = Color.FromArgb(255, 255, 192)
          End If
  
          If Len(theMessage) &lt;= 30 Then
              howLong = 4000
          ElseIf Len(theMessage) &gt;= 31 And Len(theMessage) &lt;= 80 Then
              howLong = 7000
          ElseIf Len(theMessage) &gt;= 81 And Len(theMessage) &lt;= 100 Then
              howLong = 12000
          Else
              howLong = 17000
          End If
  
          Me.opacityTimer.Start()
      Else
          Me.Close()
      End If
  End Sub
  
  Private Sub opacityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opacityTimer.Tick
      If isLoading Then
          Me.Opacity += 0.07
  
          If Me.Opacity &gt;= 0.8 Then
              Me.opacityTimer.Stop()
              Me.opacityTimer.Dispose()
              isLoading = False
              Pause(howLong)
              Me.opacityTimer.Start()
          End If
      Else
          Me.Opacity -= 0.08
  
          If Me.Opacity &lt;= 0 Then
              Form2.theNumOpened = Form2.theNumOpened - 1 'ADDED
              Me.opacityTimer.Stop()
              Me.Close()
              Me.Dispose()
          End If
      End If
  End Sub
  
  Public Sub Pause(ByVal Milliseconds As Integer)
      Dim dTimer As Date
  
      dTimer = Now.AddMilliseconds(Milliseconds)
  
      Do While dTimer &gt; Now
          Application.DoEvents()
      Loop
  End Sub
  </code></pre>
  
  <p>And how i call it is like this:</p>
  
  <pre><code> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      Dim theForm As New frmInfo2
  
      Call theForm.showMessageBox("MID", "This is just a simple test here! And some more text to see how longer it is." &amp; theNum)
      theNum = theNum + 1
   End Sub
  </code></pre>
  
  <p>David</p>