asked on
Private Sub Panel1_Click(sender As Object, e As EventArgs) Handles Panel1.Click
MessageBox.Show("Short Strings will be created, click to continue, this process. its 1 sql event which takes about 4 minutes, so wait for the next message as progress bar wont update with this procedure call. after clicking ok")
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1 * 1000
Timer1.Start()
Call CreateAllStrs()
Timer1.Stop()
MessageBox.Show("Short Strings Created")
Me.Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ProgressBar2.Value <= 10000 Then
ProgressBar2.Value = ProgressBar2.Value + 1
ProgressBar2.PerformStep()
Else
ProgressBar2.Value = 1
End If
End Sub
ASKER
ASKER
ASKER
Imports System.ComponentModel
Public Class Form1
Dim AllListBox As New List(Of ListBox)()
Private dtWords As DataTable
'Private backgroundWorker1 As BackgroundWorker = New BackgroundWorker
Public Sub New()
InitializeComponent()
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.WorkerSupportsCancellation = True
End Sub
Private Sub startAsyncButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Panel1.Click
If backgroundWorker1.IsBusy <> True Then
' Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync()
End If
End Sub
Private Sub cancelAsyncButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles StrShortCancel.Click
If backgroundWorker1.WorkerSupportsCancellation = True Then
' Cancel the asynchronous operation.
backgroundWorker1.CancelAsync()
End If
End Sub
'This Event handler() Is where the time-consuming work Is done.
Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object,
ByVal e As DoWorkEventArgs) Handles backgroundWorker1.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Dim i As Integer
For i = 1 To 10
If (worker.CancellationPending = True) Then
e.Cancel = True
Exit For
Else
' Perform a time consuming operation and report progress.
System.Threading.Thread.Sleep(500)
worker.ReportProgress(i * 10)
End If
Next
End Sub
'This Event handler() updates the progress.
Private Sub backgroundWorker1_ProgressChanged(ByVal sender As System.Object,
ByVal e As ProgressChangedEventArgs) Handles backgroundWorker1.ProgressChanged
ResultLabel.Text = (e.ProgressPercentage.ToString() + "%")
Me.ProgressBar2.Value = e.ProgressPercentage
End Sub
' This event handler deals with the results of the background operation.
Private Sub backgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object,
ByVal e As RunWorkerCompletedEventArgs) Handles backgroundWorker1.RunWorkerCompleted
If e.Cancelled = True Then
ResultLabel.Text = "Canceled!"
ElseIf e.Error IsNot Nothing Then
ResultLabel.Text = "Error: " & e.Error.Message
Else
ResultLabel.Text = "Done!"
End If
End Sub
Public Sub CreateAllStrs()
'ProgressBar2.Visible = True
'ProgressBar2.Minimum = 0
' ProgressBar2.Maximum = 10000
' ProgressBar2.Value = 0
' ProgressBar2.Step = 1
'LBLBulkWait.Visible = True
Dim StrProcName As String
StrProcName = "usp_CreateStrStringsPlusTidyup"
Dim connectionString As String = ConfigurationManager.ConnectionStrings("Dictionary").ConnectionString
Using conn As New SqlConnection(connectionString)
Using cmd As New SqlCommand(StrProcName, conn)
cmd.CommandTimeout = 0
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
cmd.ExecuteScalar()
End Using
End Using
'ProgressBar2.Visible = False
'LBLBulkWait.Visible = False
End Sub
ASKER
ASKER
Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object,
ByVal e As DoWorkEventArgs) Handles backgroundWorker1.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Dim i As Integer
For i = 1 To 10
If (worker.CancellationPending = True) Then
e.Cancel = True
Exit For
Else
' Perform a time consuming operation and report progress.
Call CreateAllStrs()
System.Threading.Thread.Sleep(500)
worker.ReportProgress(i * 10)
End If
Next
End Sub
ASKER
Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,
TRUSTED BY
ASKER