title: wpf forcing update UI window during a procedure
body: <p>I need only to show a custom control (a clock with rotating hands) and with this to replace the mouse cursor, if I use a file .cur or .ani to replace the mouse cursor
  Me.CUrsor = New Cursor("absolute path of the .ani file")
  there is no problem: I can change the cursor during a procedure: but the quality of the animation is very bad, and, also for other reasons, I'd prefer to use my little user-control. The problem is that if I write:</p>
  
  <p>Me.gridScreen.Visibility = Visibility.Visible</p>
  
  <p>' some operations that takes about 1 second</p>
  
  <p>Me.gridScreen.Visibility = Visibility.Hidden</p>
  
  <p>(gridScreen is the grid that contains the user-control)</p>
  
  <p>Obviously I can see nothing, because the update of the UI happens at the end of the procedure. I have tried Me.UpdateLayout(), but it doesn't work.</p>
  
  <p>I have tryed to use the dispacker in many way but none that works :-(</p>
  
  <p>This is my lost attempt:</p>
  
  <p>(uCurClock is the usercontrol, gridScreen a Grid placed at the top-level in the window, with trasparent background, that contains the usercontrol)</p>
  
  <pre><code>Private Sub showClock()G
      Dim thread = New System.Threading.Thread(AddressOf showClockIntermediate)
      thread.Start()
  End Sub
  
  Private Sub hideClock()
      Dim thread = New System.Threading.Thread(AddressOf hideClockIntermediate)
      thread.Start()
  End Sub
  
  Private Sub showClockIntermediate()
      Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New Action(AddressOf showClockFinale))
  End Sub
  
  Private Sub hideClockIntermediate()
      Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New Action(AddressOf hideClockFinale))
  End Sub
  
  Private Sub showClockFinale()
      Dim pt As Point = Mouse.GetPosition(Nothing)
      Me.uCurClock.Margin = New Thickness(pt.X - 9, pt.Y - 9, 0, 0)
      Me.gridScreen.Visibility = Visibility.Visible
      Me.Cursor = Cursors.None
      Me.UpdateLayout()
  End Sub
  
  Private Sub hideClockFinale()
      Me.gridScreen.Visibility = Visibility.Hidden
      Me.Cursor = Cursors.Arrow
      Me.UpdateLayout()
  End Sub
  
  Private Sub u_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseMove
      Dim pt As Point = e.GetPosition(Nothing)
      Me.uCurClock.Margin = New Thickness(pt.X - 9, pt.Y - 9, 0, 0)
  
      e.Handled = True
  End Sub
  
  Private Sub u_MouseEnter(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseEnter
      Me.uCurClock.Visibility = Visibility.Visible
  
      e.Handled = True
  End Sub
  
  Private Sub u_MouseLeave(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseLeave
      Me.uCurClock.Visibility = Visibility.Hidden
  
      e.Handled = True
  End Sub
  </code></pre>
  
  <p>PIleggi </p>