因此,我有一个带有平数的类来帮助我处理进度栏阶段,一个带有工作子类的子类来完成这项工作,而我有一个带有他自己事件的子类,我刚刚从主类中复制了这个子类。问题是子类中的事件根本不起作用。我不知道为什么真的。
这就是我的代码的样子:
Class FolderHelper
'Thats my progressbar eventhandler. It is OK
Private Shared _StageCompleted As Integer
Public Shared Event MyProgressChanged(ByVal CurStage As Integer)
Public Shared Property StageCompleted() As Integer
Get
Return _StageCompleted
End Get
Set(ByVal CurProgress As Integer)
_StageCompleted = CurStage
'This event is OK.
RaiseEvent MyProgressChanged(CurStage)
End Set
End Property
Private Sub RefreshProgress() Handles Me.MyProgressChanged
'Some progressbar stuff here
End Sub
'This is my subclass with malfunction event
Public Class ParseNames
Private Shared _FilePath As String
Public Shared Event NewFilePath(ByVal NewFile As String)
Public Shared Property FilePath() As String
Get
Return _FilePath
End Get
Set(ByVal NewFile As String)
_FilePath = NewFile
'Problem here. Event doesnt fire.
'But its completely copies event in class above.
RaiseEvent NewFilePath(NewFile)
End Set
End Property
Private Sub AnalyzeNewFile(ByVal NewFile As String) Handles MyClass.NewFilePath
'Some work here
End Sub
End Class
'class with some work subs...
Public class DoWorks
Private Sub DoWork()
'Thats what has to call a work
'This variable set is NOT ok with firing event
Folder_helper.ParseNames.Filepath = SomeNewFile
'This one IS ok
Folder_helper.StageCompleted +=1
End Sub
End class
End Class好的。奥斯卡去冥王星:)
发布于 2014-05-22 15:54:15
代码必须像这样才能工作:
Class FolderHelper
'Create an instance of my private class which is listening to events
Public Shared WithEvents PN As New ParseNames
Public Class ParseNames
'Same strings as above...
End class
'All others strings are the same except...
Public class DoWorks
Private Sub DoWork()
'I has to call my newly created instance of ParseNames which is "WithEvents"
PN.Filepath = SomeNewFile
Folder_helper.StageCompleted +=1
End Sub
End class端级
https://stackoverflow.com/questions/23088258
复制相似问题