Question

I have the following code that adds a background worker into a VB.net WPF project:

Imports System
Imports System.ComponentModel
Imports System.ComponentModel.BackgroundWorker
Imports System.IO
Imports System.Threading
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports System.ServiceProcess
Partial Public Class Window1
Public Sub New()
    MyBase.New()
    Me.InitializeComponent()
    End Sub
End Class
Public Class Window1
Dim worker As New BackgroundWorker
Private Sub worker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.BackgroundWorker) Handles worker.DoWork

   End Sub
End Class

And I get the following error for the DoWork worker event:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

It seems like it's missing something in the Event declaration, but can't find it.

Any ideas?

Was it helpful?

Solution

The signature of your DoWork event looks funky - shouldn't it be (Object, DoWorkEventArgs).

You have (Object, BackgroundWorker)

OTHER TIPS

Try adding 'WithEvents' when declaring the new backgroundworker. Below is a snippet of code from one of my backgroundworker objects from the Windows Form Designer Generated Code:

Friend WithEvents bWorker As System.ComponentModel.BackgroundWorker

Let me know if this helps!

try replacing

Dim worker As New BackgroundWorker

with

Private WithEvents worker As New BackgroundWorker
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top