title: Using GetActiveWindow()
body: <p>I have a timer in my application (timer1). When this timer goes off, it calls a sub that refreshes my datagridview. Before calling the refresh sub, I use GetActiveWindow() from user32 Lib to check If the form is the active window. This works as expected. Here is the code I am using to check the active window. </p>
  
  <pre><code>If Me.Handle = GetActiveWindow() Then
      gridRefresh()
  Else
      MessageBox.Show("Works")
  End If
  </code></pre>
  
  <p>I included the messagebox just to give me a visual that It is indeed working when the active window is not my Application. </p>
  
  <p>What I am missing though is I would like to call the gridRefresh() sub once my Application becomes the active window again. </p>
  
  <p>My first thought would be to use a Do Until loop and have it do nothing until It becomes the active window again like so:</p>
  
  <pre><code>If Me.Handle = GetActiveWindow() Then
      gridRefresh()
  Else
      Do Until Me.Handle = GetActiveWindow()
  
      Loop
      gridRefresh()
  End If
  </code></pre>
  
  <p>But when I try this solution It never comes out of the loop. </p>
  
  <p>Edit: The timer interval is 1 minute. The reason I want it to refresh once it becomes active again is so the user doesn't have to wait a whole minute to see if anything has been added to the gridview</p>