frmProgress.cs
Multithreaded raster subset
frmProgress.cs
// Copyright 2006 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SubsetRasterLayer
{
  public partial class frmProgress : Form
  {
    private delegate void IncrementProgressBarCallback(int barNo);
    private delegate void SetProgressBarMaximumCallback(int maxVal);
    private delegate void CloseDlgCallback();
    private delegate void SetStatusBarMessageCallback(string msg);

    public frmProgress()
    {
      InitializeComponent();
    }

    public void IncrementProgressBar(int barNo)
    {
      // InvokeRequired required compares the thread ID of the
      // calling thread to the thread ID of the creating thread.
      // If these threads are different, it returns true.
      if (this.InvokeRequired)
      {
        //call itself on the main thread
        IncrementProgressBarCallback d = new IncrementProgressBarCallback(IncrementProgressBar);
        this.Invoke(d, new object[] { barNo });
      }
      else
      {
        switch (barNo)
        {
          case 1:
            progressBar1.Increment(1);
            break;

          case 2:
            progressBar2.Increment(1);
            break;

          case 3:
            progressBar3.Increment(1);
            break;
        }
      }
    }

    public void SetProgressbarMaximum(int maxVal)
    {
      if (this.InvokeRequired)
      {
        //call itself on the main thread
        SetProgressBarMaximumCallback d = new SetProgressBarMaximumCallback(SetProgressbarMaximum);
        this.Invoke(d, new object[] { maxVal });
      }
      else
      {
        progressBar1.Maximum = maxVal;
        progressBar2.Maximum = maxVal;
        progressBar3.Maximum = maxVal; 
         
      }
    }

    public void CloseDlg()
    {
      if (this.InvokeRequired)
      {
        CloseDlgCallback d = new CloseDlgCallback(CloseDlg);
        this.Invoke(d);
      }
      else
      {
        this.Close();
        
      }
    }

    public void SetStatusBarMessage(string msg)
    {
      if(this.InvokeRequired)
      {
        SetStatusBarMessageCallback d = new SetStatusBarMessageCallback(SetStatusBarMessage);
        this.Invoke(d, new object[] { msg });
      }
      else
      {
        this.statusLabel.Text = msg;
      }
    }
  }
}