title: VLC frame freezing on WPF user interface
body: <p>I have a WPF user interface which is contains 2 <a href="https://github.com/ZeBobo5/Vlc.DotNet" rel="nofollow">Vlc.DotNet</a> element and some <code>Image</code> and <code>Datagrid</code>es that are updating frequently.<br>
  Each of These 2 VLC elements plays a stream from file or IP-Camera.<br>
  Other elements on the UI, update frequently during every minute and it's not a routine action. The instruction of these updates are coming from another <code>Thread</code> in the program and update UI with <code>Invoke</code>.</p>
  
  <p>The problem is the VLC player element, freezes on a random frame.<br>
  Any idea about the possible causes?  </p>
  
  <p>Additional info: I'm using VLC 2.2.0 x86 and VS2013.</p>
  
  <p><strong>Edit</strong>: Adding some code:</p>
  
  <p>WPF Code:</p>
  
  <pre><code>&lt;Grid Name="_cameraBox" FlowDirection="LeftToRight" Visibility="Collapsed" &gt;
      &lt;vlc:VlcControl x:Name="myVlcControl1" /&gt;
      &lt;Grid&gt;
          &lt;Grid.Background&gt;
              &lt;VisualBrush Stretch="Fill"&gt;
                  &lt;VisualBrush.Visual&gt;
                      &lt;Border BorderBrush="Black" BorderThickness="12" CornerRadius="10"&gt;
                          &lt;Viewbox&gt;
                              &lt;Image Source="{Binding ElementName=myVlcControl1, Path=VideoSource}" /&gt;
                          &lt;/Viewbox&gt;
                      &lt;/Border&gt;
                  &lt;/VisualBrush.Visual&gt;
              &lt;/VisualBrush&gt;
          &lt;/Grid.Background&gt;
          &lt;Image Source="/Resources/Images/Logo.png" Stretch="Uniform" Margin="10"/&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>C# code:</p>
  
  <pre><code>private void LoadTheStream(int streamNumber, string streamAddress)
  {
      Dispatcher.Invoke(new Action(() =&gt;
      {           
          if(InitialPrameters.UsingViedo)
          {
              streamAddress = "file:///" + streamAddress;
          }
          var vlc = (Vlc.DotNet.Wpf.VlcControl) this.FindName("myVlcControl" + streamNumber.ToString());
          vlc.Stop();
          vlc.Media = new LocationMedia(streamAddress);
          vlc.Play();
      }));
  }
  </code></pre>
  
  <p>and Events to Update UI code:</p>
  
  <pre><code>private void UpdateImageOnUI(object sender, EventArgs e)
  {
      var args = e as UIUpdateEventArgs;
      ShowTheFrame(args.StreamNumber, args.SnapShot, args.FrameCrop);
  }
  
  private void ShowDetectedFrame(int streamNumber, Bitmap snapShot, Bitmap frameCrop)
  {
      Dispatcher.Invoke(new Action(() =&gt;
      {
          var snapShotCtrl = (System.Windows.Controls.Image) FindName("_snapShot" + streamNumber.ToString());
          var frameCropCtrl = (System.Windows.Controls.Image) FindName("_frameCrop" + streamNumber.ToString());
  
          var snapShotImage = GeneralFunctions.ConvertToBitmapImageFromBitmap(snapShot);
          var frameCropImage = GeneralFunctions.ConvertToBitmapImageFromBitmap(frameCrop);
  
          snapShotCtrl.Source = snapShotImage;
          frameCropCtrl.Source = frameCropImage;
  
          snapShotImage.Freeze();
          frameCropImage.Freeze();
      }));
  }
  </code></pre>