title: I wish to avoid form freezing during load large files to show
body: <p>I made my own FilePreviewHandler for preview some files like Explorer because currently I made custom file browser.</p>
  
  <p>When I click items on ListView, I can preview files like explorer.</p>
  
  <p>The PreviewHandler which is in my file browser Contains WebBrowser Class for load Movie/Text files,
  PictureBox for load Image files, and ShellExPreviewHandler for other extensions.</p>
  
  <p>The problem which engaged is like this.</p>
  
  <p>When I attempt to load large file such 100mb or more large file or big image file like 8000x4000 pixels, form freezes until it load file.</p>
  
  <p><strong>Code Area for PreviewHandler :</strong></p>
  
  <pre><code>    public void Open( String FileName )
      {
          if ( !Enabled || Last == FileName )
          {
              return;
          }
          //FileName = DriveUtil.RevealPath( FileName );
  
          String FileType = MIMEAssistant.GetMIMEType( FileName );
          // Image Files
          if ( ImagePreviewTarget.Where( x =&gt; FileType.Contains( x ) ).Count() &gt; 0 )
          {
              IsProgress = true;
              try
              {
                  if ( ImagePreviewHandler.Image != null )
                  {
                      ImagePreviewHandler.Image.Dispose();
                      GC.Collect();
                  }
                  Image TargetImage = Image.FromFile( FileName );
                  if ( TargetImage.Width &gt; this.Width || TargetImage.Height &gt; this.Height )
                  {
                      ImagePreviewHandler.SizeMode = PictureBoxSizeMode.Zoom;
                  }
                  else
                  {
                      ImagePreviewHandler.SizeMode = PictureBoxSizeMode.CenterImage;
                  }
                  ImagePreviewHandler.Image = TargetImage;
                  ImagePreviewHandler.BringToFront();
              }
              catch
              {
                  ImagePreviewHandler.Image = null;
                  GC.Collect();
                  ShellExPreviewHandler.BringToFront();
                  IsProgress = false;
              }
          }
  
  
          // WebPreviewArea
          // This area doesn't make any problem. So I hide my codes on here.
  
  
          // PdfPreviewArea
          // Currently I don't use Pdf PreviewHandler. So I also hide my codes on here.
  
          // Other extensions
          else
          {
              ShellExPreviewHandler.Open( FileName );
              ShellExPreviewHandler.BringToFront();
          }
  
          Last = FileName;
      }
  </code></pre>
  
  <p><strong>What I Tried :</strong></p>
  
  <p>I tried to use Thread, Task.Run, Backgroundworker for this, but all of this requires MyForm.Invoke to draw controls.</p>
  
  <p>Thread Part => </p>
  
  <pre><code>        Thread Preview = new Thread( (ThreadStart) =&gt;
          {
              try
              {
                  if ( FilePreview != null &amp;&amp; Browser.PreviewOpened )
                  {
                      Console.WriteLine( "FilePreview.Open Task Start" );
                      FilePreview.Open( Browser.SelectedPath );
                      Console.WriteLine( "FilePreview.Open Task Completed" );
                  }
              }
              catch ( Exception ex )
              {
                  Console.WriteLine( ex.StackTrace );
              }
  
              Process = false;
          } );
  
          Preview.Start();
          if ( Preview.Join( TimeSpan.Zero ) )
          {
              DateTime dt = DateTime.Now;
              TimeSpan Interval = TimeSpan.FromMilliseconds( 50 );
              while ( Process )
              {
                  if ( dt + Interval &lt; DateTime.Now )
                  {
                      Application.DoEvents();
                      dt = DateTime.Now;
                  }
              }
          }
  </code></pre>
  
  <p>Task.Run Part => </p>
  
  <pre><code>var t = Task.Run( () =&gt;
          {
              try
              {
                  this.Invoke( new MethodInvoker( delegate
                  {
                      if ( Browser.SelectedItems.Count == 0 )
                      {
                          FilePreview.Initialize(); 
                          return;
                      }
                      else if ( Browser.SelectedItems[0].ForeColor == Color.Pink )
                      {
                          FilePreview.Initialize();
                          return;
                      }
  
                      if ( FilePreview != null &amp;&amp; Browser.PreviewOpened )
                      {
                          FilePreview.Open( Browser.SelectedPath );
                      }
                  } ) );
              }
              catch
              {
  
              }
          } );
  </code></pre>
  
  <p>BackgroundWorker => </p>
  
  <pre><code>    private void PreviewWorker_DoWork( object sender, DoWorkEventArgs e )
      {
          FilePreviewHandler FilePreview = null;
          GCS.Windows.Forms.FileFolderList Browser = null;
  
          switch ( PreviewStatus ) {
              case BrowserStatus.Local:
                  FilePreview = LocalFilePreviewHandler;
                  Browser = LocalBrowser;
                  break;
              case BrowserStatus.Network:
                  FilePreview = NetFilePreviewHandler;
                  Browser = NetworkBrowser;
                  break;
          }
  
          if ( FilePreview == null )
          {
              return;
          }
  
          this.Invoke( new MethodInvoker( delegate
          {
              FilePreview.Open( Browser.SelectedPath );
          } ) );
      }
  </code></pre>
  
  <p>I think this part makes my program freezing.</p>
  
  <p>any idea to avoid form freezing during load large files for PreviewHandler?</p>