Raising Events from a class library
-
I am in a scenario where I have made a class library (*.dll) file. At some point I need to raise an event( from within a class of the *.dll library) of a class(Like Event in the Class shown Below) which is outside or out of the scope of the *.dll library. How do I do it? Do I need to add interface in that particular class of the *.dll library and implement in the calling class or any technique? Does anybody have some idea? Public Class SomeClass Public Event SomeEvent .......... End Class
-
I am in a scenario where I have made a class library (*.dll) file. At some point I need to raise an event( from within a class of the *.dll library) of a class(Like Event in the Class shown Below) which is outside or out of the scope of the *.dll library. How do I do it? Do I need to add interface in that particular class of the *.dll library and implement in the calling class or any technique? Does anybody have some idea? Public Class SomeClass Public Event SomeEvent .......... End Class
There's no magical difference between events in a Form and events in a class library. A Form is just another class. The code snippet you've posted is correct. You just have to keep going and flesh it out with an Event Args class of your own making and add some code that raises the event.
Public Class SomeClass
Public Event WorkCompleted(ByVal e As WorkCompletedEventArgs) ... RaiseEvent WorkCompleted(New WorkCompletedEventArgs(someValue, someOtherValue)) ...
End Class
Public Class WorkCompletedEventArgs
' Expose Public properties that will
' return values to the subscriber.
' You might want to include a New (constructor)
' that set's these values instead of just
' relying on an empty constructor.Public Sub New(ByVal value1 As Integer, ByVal value2 As String) Me.myValue = value1 Me.myString = value2 End Sub
End Class
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008modified on Tuesday, April 28, 2009 12:38 AM