codice:Imports System.Threading Public Class Form1 Dim t As Thread Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ProgressBar1.Minimum = 0 ProgressBar1.Maximum = 1000 t = New Threading.Thread(AddressOf LoadingProgressBar) t.Start() End Sub Private Sub LoadingProgressBar() Try Dim i As Integer Dim progress As Integer = 0 For i = 0 To 1000 Me.Invoke(up, i) Me.Invoke(updateStatus, i) Me.Invoke(msg, i) Thread.Sleep(1000) Next Me.Invoke(closeForm) Catch ex As ThreadAbortException Err.Clear() Me.Invoke(closeForm) End Try End Sub 'Delegate method to allows other thread to update value of Progress Bar Private Delegate Sub updateProgress(ByVal val As Integer) Private up As New updateProgress(AddressOf UpdateValue) 'Delegate method to allows other thread to close Private Delegate Sub closeMe() Private closeForm As New closeMe(AddressOf CloseSplash) 'Delegate method to allows other thread to update text of Label Status Private Delegate Sub setStatus(ByVal status As Integer) Private updateStatus As New setStatus(AddressOf WriteLabel) Private Delegate Sub message(ByVal i As Integer) Private msg As New message(AddressOf messaggio) 'UpdateValue method has been implemented to update value of progress Bar Private Sub UpdateValue(ByVal val As Integer) ProgressBar1.Value = val End Sub 'WriteLabel Private Sub WriteLabel(ByVal text As String) lbl.Text = text End Sub Private Sub messaggio(i As Integer) MsgBox(i) End Sub 'Close Private Sub CloseSplash() Me.Close() End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click t.Abort() End Sub End Class
Grazie a te le cose adesso sono piu chiare, questo è un estratto d'esempio.
quando parte il MSGbox il trhead si blocca quindi non è possibile adortire da tasto, invece io vorrei avere la possibilità di abortirlo ugualmente cliccando il Button1

Rispondi quotando