Beispiel #1
0
    public static EventSubscriptionToken FromEvent(
        Action <EventHandler> addHandler,
        Action <EventHandler> removeHandler,
        EventHandler handler,
        HandlerThreadOption threadOption)
    {
        var threadSpecificHandler = GetHandler(handler, threadOption);

        addHandler(threadSpecificHandler);

        return(new EventSubscriptionToken(() => removeHandler(threadSpecificHandler)));
    }
Beispiel #2
0
    private static EventHandler GetHandler(EventHandler handler, HandlerThreadOption threadOption)
    {
        switch (threadOption)
        {
        case HandlerThreadOption.PublisherThread:
            return(handler);

        case HandlerThreadOption.SubscriberThread:
            return(GetCurrentThreadExecutionStrategy(handler));

        case HandlerThreadOption.BackgroundThread:
            return(GetBackgroundThreadExecutionStrategy(handler));

        default:
            throw new ArgumentOutOfRangeException("threadOption");
        }
    }