Re: Fortschrittsbalken für Funktion
- From: "Peter Fleischer" <peter.fleischer_nospam_@xxxxxx>
- Date: Sat, 24 Jun 2006 20:04:45 +0200
Mathias Kant wrote:
....
Er gibt leider ein Fehler aus: Ungültiger threadübergreifender
Vorgang.
Mathias,
besser ist es, in der Routine, die die Callback-Roitine aufruft, den
thread-übergriefenden Zugriff mittels Invoke auszuführen, z.B. so:
Private pb As New ProgressBar
Private endflag As Boolean
Delegate Sub ShowProgress()
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Prepare stop ProgressBar with any KeyDown
With Me
.KeyPreview = True
AddHandler .KeyDown, AddressOf StopPd
End With
'
With pb
.Dock = DockStyle.Top
Me.Controls.Add(pb)
End With
' Create a delegate that points to it.
Dim asyncFill As New ShowProgress(AddressOf ExecProgress)
' Open it asynchronously - pass the delegate as the cookie.
Dim ar As IAsyncResult = _
asyncFill.BeginInvoke(AddressOf ShowComplete, asyncFill)
'...
' main process
'Form1.autom.automatKlass(Form1.ComboBox1.Text, Form1.xmldoc).OuterXml
'...
End Sub
Private Sub StopPd(ByVal sender As Object, ByVal e As KeyEventArgs)
endflag = True
End Sub
Private Sub IncrementValuePb()
With pb
If .InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf IncrementValuePb))
Else
If .Value = .Maximum Then
.Value = 0
Else
.Value += 1
End If
End If
End With
End Sub
' this method is called when the operation is completed
Private Sub ShowComplete(ByVal ar As IAsyncResult)
' retrieve a reference to the delegate.
Dim asyncFill As ShowProgress = CType(ar.AsyncState, ShowProgress)
Try
' Complete the operation.
asyncFill.EndInvoke(ar)
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub
' Show ProgressBar and animate
Private Sub ExecProgress()
' reset End-Flag
endflag = False
' ProgressBar
Do Until endflag Or Me.IsDisposed
IncrementValuePb()
System.Threading.Thread.Sleep(50)
Loop
End Sub
Peter
.
- References:
- Fortschrittsbalken für Funktion
- From: Mathias Kant
- Re: Fortschrittsbalken für Funktion
- From: Peter Fleischer
- Re: Fortschrittsbalken für Funktion
- From: Mathias Kant
- Re: Fortschrittsbalken für Funktion
- From: Peter Fleischer
- Re: Fortschrittsbalken für Funktion
- From: Mathias Kant
- Re: Fortschrittsbalken für Funktion
- From: Peter Fleischer
- Re: Fortschrittsbalken für Funktion
- From: Mathias Kant
- Fortschrittsbalken für Funktion
- Prev by Date: Re: Datenquelle für Report (Microsoft.Reporting)
- Next by Date: Re: Fortschrittsbalken für Funktion
- Previous by thread: Re: Fortschrittsbalken für Funktion
- Next by thread: Re: Fortschrittsbalken für Funktion
- Index(es):
Relevant Pages
|