frmProgress.vb
Multithreaded raster subset
frmProgress.vb
' 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.


Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Partial Public Class frmProgress
  Inherits Form
  Private Delegate Sub IncrementProgressBarCallback(ByVal barNo As Integer)
  Private Delegate Sub SetProgressBarMaximumCallback(ByVal maxVal As Integer)
  Private Delegate Sub CloseDlgCallback()
  Private Delegate Sub SetStatusBarMessageCallback(ByVal msg As String)

  Public Sub New()
    InitializeComponent()
  End Sub

  Public Sub IncrementProgressBar(ByVal barNo As Integer)
    ' 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 Me.InvokeRequired Then
      'call itself on the main thread
      Dim d As IncrementProgressBarCallback = New IncrementProgressBarCallback(AddressOf IncrementProgressBar)
      Me.Invoke(d, New Object() {barNo})
    Else
      Select Case barNo
        Case 1
          progressBar1.Increment(1)

        Case 2
          progressBar2.Increment(1)

        Case 3
          progressBar3.Increment(1)
      End Select
    End If
  End Sub

  Public Sub SetProgressbarMaximum(ByVal maxVal As Integer)
    If Me.InvokeRequired Then
      'call itself on the main thread
      Dim d As SetProgressBarMaximumCallback = New SetProgressBarMaximumCallback(AddressOf SetProgressbarMaximum)
      Me.Invoke(d, New Object() {maxVal})
    Else
      progressBar1.Maximum = maxVal
      progressBar2.Maximum = maxVal
      progressBar3.Maximum = maxVal

    End If
  End Sub

  Public Sub CloseDlg()
    If Me.InvokeRequired Then
      Dim d As CloseDlgCallback = New CloseDlgCallback(AddressOf CloseDlg)
      Me.Invoke(d)
    Else
      Me.Close()

    End If
  End Sub

  Public Sub SetStatusBarMessage(ByVal msg As String)
    If Me.InvokeRequired Then
      Dim d As SetStatusBarMessageCallback = New SetStatusBarMessageCallback(AddressOf SetStatusBarMessage)
      Me.Invoke(d, New Object() {msg})
    Else
      Me.statusLabel.Text = msg
    End If
  End Sub
End Class