'How to unsubscribe an event from inside the event handler?

My code subscribes to an event and it needs to unsubscribe (Dispose) once the event has been handled. However this looks like a chicken-egg problem. Using rec doesn't work and I cannot find how to do it.

It there any well-konwn pattern to bypass this limitation?

let process = new Process()
let exitSubscription = process.Exited.Subscribe (
    fun evntArg ->
        exitSubscription.Dispose()     <---------- Compiler complains here
        // do more something here.
     )
f#


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source