0

バックグラウンドワーカーをVB.netWPFプロジェクトに追加する次のコードがあります。

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句には、包含型またはその基本型の1つで定義されたWithEvents変数が必要です。

イベント宣言に何かが欠けているようですが、見つかりません。

何か案は?

4

3 に答える 3

3

新しいbackgroundworkerを宣言するときに、「WithEvents」を追加してみてください。以下は、Windowsフォームデザイナで生成されたコードのbackgroundworkerオブジェクトの1つからのコードのスニペットです。

Friend WithEvents bWorker As System.ComponentModel.BackgroundWorker

これが役立つかどうか教えてください!

于 2009-03-11T17:23:48.063 に答える
3

DoWork イベントの署名はファンキーに見えます - (Object, 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 に答える