About the code of Wait Form Dialog

Steven Young 261 Reputation points
2022-12-31T13:30:32.287+00:00

I convert a C# sample to VB.NET, but one line<Dim frm As New frmWait(SaveData)> will not work, why?

The C# link
https://foxlearn.com/article/wait-form-dialog-in-csharp-114.html#:~:text=This%20post%20shows%20you%20how%20to%20create%20a,can%20layout%20your%20ui%20design%20as%20shown%20below.

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
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-12-31T16:50:35.873+00:00

    Try Dim frm As New frmWait(AddressOf SaveData).


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.