Skip to content

Thread safe invocations #238

@TKul6

Description

@TKul6

Hello,

I wanted to create an "async shell" for methods to run asynchronously.

I created an AsyncInterceptor which look like this:

public void Intercept(IInvocation invocation)
        {


            //Methods starts with add_ or remove_ are registration and unregistration methods to the class's events.
            //Those methods should be invoked synchronously
            if (invocation.Method.Name.StartsWith("add_") || invocation.Method.Name.StartsWith("remove_"))
            {
                invocation.Proceed();
            }
            else
            {
                   Task.Run(() => invocation.Proceed());
            }


       }

Unfortunately, it didn't work. For some reason the interceptor was called much more than once.

By looking at AbstractInvocation I saw the Proceed method is not thread safe ( Mostly the usage of currentInterceptorIndex ).

I wonder if there is anyway to support this kind of behavior.

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions