Question

So I have a class with eventhandler to help me handle progressbar stages, a subclass with work subs which do the job and I have a subclass with his own events which I just copied from main class. Problem is event in subclass doesnt work at all. I dont know why really.

Thats how my code looks like:

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

Ok. Oscar goes to Plutonix :)

Was it helpful?

Solution

Code HAS to be like this to work:

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

End Class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top