提升事件并处理它们

时间:2014-04-02 14:22:26

标签: .net vb.net

我试图让我的主要事件发生这个事件,但目前它没有触发并更新我班级的进度条,它被称为跟随

   Private Sub _onTransferStart(ByVal source As String, ByVal destination As String,   ByVal transferredBytes As Integer, ByVal totalBytes As Integer, ByVal message As String) Handles transfer.OnTransferStart
    RaiseEvent onTransferStart(source, destination, transferredBytes, totalBytes, message)
End Sub

然后我按照以下方式处理它,但是它没有更新我的进度条以获得一些reas但是当我在ontransferstart上设置制动点时它会显示indead show bytes下载

enter image description here

这就是我在trafnerstart上调用我的方式

 Private Sub onTransferStart(ByVal source As String, ByVal destination As String, ByVal transferredBytes As Integer, ByVal totalBytes As Integer, ByVal message As String) Handles transfer.onTransferStart
    Me.ProgressBar1.Minimum = 0
    Me.ProgressBar1.Maximum = totalBytes
    Me.tbStatus.Text = "Transfer started.."
End Sub

我应该说我已经通过后台工作人员调用它了

  Private Sub bgroundDownload_DoWork(sender As System.Object, e As  
  System.ComponentModel.DoWorkEventArgs) Handles bgroundDownload.DoWork

  Dim wcEDIimport As New wcEDIimport
 e.Result = wcEDIimport.DownloadPricat()
 End Sub

 Private Sub bgroundDownload_RunWorkerCompleted(sender As System.Object, e As   
System.ComponentModel.RunWorkerCompletedEventArgs) Handles  
bgroundDownload.RunWorkerCompleted
Dim results As Boolean = CBool(e.Result)
If results = True Then
    MessageBox.Show("The download is completed: " & results.ToString)
End If
end sub

1 个答案:

答案 0 :(得分:0)

http://msdn.microsoft.com/en-us/library/9aackb16%28v=vs.110%29.aspx

这给出了一个提升和消费事件的例子。我认为你的问题是,提升事件的类应该与使用addhandler的类不同。 你不应该在同一个类中使用raiseevent和addhandler。

示例代码:

Class A
    sub raiser()
        RaiseEvent anevent
    end sub
end class
Class B
     dim A1 as A
     sub New()
         AddHandler A1.anevent, AddressOf catchEvent
     End sub
     sub catachEvent()
          'do something here
     end sub
end class