Progressbar aus asynchronem Prozeß steuern

Public Class Form3

Private m_ToolstripProgressClass As ToolstripProgressClassPublic Sub New()‘ Dieser Aufruf ist für den Designer erforderlich.

InitializeComponent()

‘ Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

m_ToolstripProgressClass = New ToolstripProgressClass(ToolStripProgressBar1)

Dim worker As WorkerClass = New WorkerClass

AddHandler m_ToolstripProgressClass.CallbackIsReady, AddressOf Worker_End

m_ToolstripProgressClass.Start(worker, False)

End Sub

Private Sub Worker_End()

MessageBox.Show(“Asynchron-Callback”)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

m_ToolstripProgressClass = New ToolstripProgressClass(ToolStripProgressBar1)

Dim worker As WorkerClass = New WorkerClassm_ToolstripProgressClass.Start(worker, True)

m_ToolstripProgressClass.Reset()

MessageBox.Show(“Synchron-Ende”)

End Sub

End Class

Public Class ToolstripProgressClass

Public Delegate Sub AsyncValueChanged(ByVal ProgessValue As Integer)

Public Delegate Sub CallbackIsReadyDelegate(ByRef sender As Object, ByRef p_strdate As String)

Public Delegate Sub AsyncLongrunning()Public Event CallbackIsReady(ByRef sender As Object, ByRef p_date As String)

Private m_AsyncMethod As AsyncLongrunning

Private callback As AsyncCallback

Private WithEvents EndeTimer As Windows.Forms.Timer

Private WithEvents m_ToolstripProgress As System.Windows.Forms.ToolStripProgressBar

Public Sub New(ByRef ToolstripProgress As System.Windows.Forms.ToolStripProgressBar)

m_ToolstripProgress = ToolstripProgress

EndeTimer =

New Windows.Forms.TimerEndeTimer.Interval = 3000

End Sub

Public Sub Start(ByRef LongrunningWorker As IWorkerWithProgressEvent, ByVal Synchron As Boolean)

AddHandler LongrunningWorker.ProgressValueChanged, AddressOf ProgressValueChanged

If Synchron Then

LongrunningWorker.Longrunning()

Else

callback = AddressOf CallbackHandlerm_AsyncMethod = AddressOf LongrunningWorker.Longrunning

Dim asyncResult As IAsyncResult = m_AsyncMethod.BeginInvoke(callback, m_AsyncMethod)

End If

End Sub

Public Sub CallbackHandler(ByVal result As IAsyncResult)

Dim asyncmethod As AsyncLongrunning = CType(result.AsyncState, AsyncLongrunning)m_AsyncMethod.EndInvoke(result)

Dim strText As String = “Fertig”

RaiseEvent CallbackIsReady(Me, strText)

End Sub

Private Sub async_CallbackIsReady(ByRef sender As Object, ByRef p_strTxt As String) Handles Me.CallbackIsReady

If m_ToolstripProgress.Owner.InvokeRequired Then

Dim isReady As CallbackIsReadyDelegate = AddressOf async_CallbackIsReady

Dim param As Object() = New Object() {Me, p_strTxt}m_ToolstripProgress.Owner.Invoke(isReady, param)

Else

Reset()

End If

End Sub

Public Sub Reset()m_ToolstripProgress.Value = 100

EndeTimer.Start()

End Sub

Private Sub ProgressValueChanged(ByVal Value As Integer)

If m_ToolstripProgress.Owner.InvokeRequired Then

Dim ValueChanged As AsyncValueChanged = AddressOf ProgressValueChanged

Dim param As Object() = New Object() {Value}m_ToolstripProgress.Owner.Invoke(ValueChanged, param)

Else

m_ToolstripProgress.Value = Value

End If

End Sub

Private Sub EndeTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles EndeTimer.Tick

EndeTimer.Stop()

m_ToolstripProgress.Value = 0

End Sub

End Class

Public Class WorkerClass : Implements IWorkerWithProgressEvent

Public Event ProgressValueChanged(ByVal Value As Integer) Implements IWorkerWithProgressEvent.ProgressValueChanged

Public Sub LongRunning() Implements IWorkerWithProgressEvent.Longrunning

For i As Integer = 0 To 100System.Threading.Thread.Sleep(20)

RaiseEvent ProgressValueChanged(i)

Next

End Sub

End Class

Public Interface IWorkerWithProgressEvent

Event ProgressValueChanged(ByVal Value As Integer)Sub Longrunning()

End Interface

Einen Kommentar schreiben:


compare metformin to gliclazide glucophage chromium picolinate cosa mangiare a cipro nord orlistat venta peru kamagra nelle farmacie italiane plavix e impotenza voltaren tissugel controindicazioni del femara metoclopramide ileus lasix in gravidanza effetti collaterali di finasteride metoprolol toprol xl conversion voltaren gel blood sugar metoprolol tratament cialis 10 mg effetti clomid provoca corrimento prometrium 200 come si usa cialis lo vendono in farmacia viagra pepsi cola diflucan tempo azione alternative naturali al clomid voltaren emulgel tendonitis voltaren generico prezzo antibiotico augmentin sospensione voltaren pastiglie senza ricetta metoprolol succinate 100 mg ter luvox period voltaren dispers 600 panière allegra tupperware propecia cinsel clindamycin molluscum contagiosum hot voltaren retard prezzo