0

我有以下代码将后台工作人员添加到 VB.net WPF 项目中:

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

对于 DoWork 工作人员事件,我收到以下错误:

Handles 子句需要在包含类型或其基类型之一中定义的 WithEvents 变量。

似乎它在事件声明中丢失了一些东西,但找不到它。

有任何想法吗?

4

3 回答 3

3

在声明新的后台工作人员时尝试添加“WithEvents”。下面是来自 Windows 窗体设计器生成代码的我的一个后台工作者对象的代码片段:

Friend WithEvents bWorker As System.ComponentModel.BackgroundWorker

让我知道这是否有帮助!

于 2009-03-11T17:23:48.063 回答
3

DoWork 事件的签名看起来很时髦 - 不应该是(对象,DoWorkEventArgs)。

你有(对象,BackgroundWorker)

于 2009-03-11T17:31:17.703 回答
2

尝试更换

Dim worker As New BackgroundWorker

Private WithEvents worker As New BackgroundWorker
于 2009-03-11T17:25:28.480 回答