Try Dim frm As New frmWait(AddressOf SaveData).
About the code of Wait Form Dialog
Steven Young
261
Reputation points
I convert a C# sample to VB.NET, but one line<Dim frm As New frmWait(SaveData)> will not work, why?
My Code:
Public Class frmWait
Public Property Worker() As Action
Public Sub New(ByVal worker As Action)
InitializeComponent()
If worker Is Nothing Then
Throw New ArgumentNullException()
End If
worker = worker
End Sub
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
'Start new thread to run wait form dialog
Task.Factory.StartNew(Worker).ContinueWith(Sub(t)
Me.Close()
End Sub, TaskScheduler.FromCurrentSynchronizationContext())
End Sub
End Class
On the main form:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Open wait form dialog
Dim frm As New frmWait(SaveData) 'This line error, why?
frm.ShowDialog(Me)
End Sub
Private Sub SaveData()
'Add code to process your data
For i As Integer = 0 To 500
Thread.Sleep(10) 'Simulator
Next i
End Sub
Developer technologies | Windows Forms
1,931 questions