The examples in this topic show how to work with events. They include examples of the TClrEventHandler and TClrEventHandlerR standard function pointers. There are examples which does not use the Clr Standard function pointers. A new function pointer will be created whose signature matches the signature of the eventhander method defined in c#.
The examples use concepts described in the Handling and Raising Events article.
Example 1
The first example shows how to raise and consume an event that doesn't have data. It contains a class named Counter that has an event named ThresholdReached. This event is raised when a counter value equals or exceeds a threshold value. The TClrEventHandler function pointer is associated with the event, because no event data is provided.
Assuming you have a C# class as shown below which is compiled to Counter.dll.
Example 2
The next example shows how to raise and consume an event that provides data. The TClrEventHandler function pointer is associated with the event, and an instance of a custom event data object is provided.
Assuming you have a C# class as shown below which is compiled to Counter.dll.
Example 3
The next example shows how to raise and consume an event that provides data. The TClrEventHandlerR function pointer is associated with theAssemblyResolve event.
Example 4
The next example shows how to raise and consume an event without using the standard Clr function Pointers (TClrEventHandlerR or TClrEventHandler). A new function pointer is created whose signature matches the signature of the eventhandler method in c#. Assuming you have a C# class as shown below which is compiled to Counter.dll.