Unregistering events
At some point after you have registered an event, the event may no longer be needed. To unregister an event, use the standard syntax for either C# or Visual Basic. You can unregister the following types of events:
- Procedure events
- Function events
- Modal dialog events
Warning: The other types of events cannot be unregistered. If you try to unregister them, an exception will be thrown.
C#
The following C# example shows how you would unregister an AfterModalDialog event. The method named IvItemMaintenance_AfterModalDialog had been registered as the event handler for the modal dialog event.
ItemMaintenanceForm.IvItemMaintenance.AfterModalDialog -= new EventHandler<AfterModalDialogEventArgs>(IvItemMaintenance_AfterModalDialog);
Visual Basic
The following Visual Basic example shows how you would unregister the InvokeAfterOriginal event for the AddSuccessfulLoginRecord procedure. The method named AddSuccessfulLogin had been registered as the event handler for the procedure event.
RemoveHandler Dynamics.Procedures.AddSuccessfulLoginRecord.InvokeAfterOriginal, _ AddressOf AddSuccessfulLogin