C# Code Resource - AsyncTaskCodeActivity

Ever build a custom code activity and wish you could just use a Task or Task<T> instead of the older BeginExecute() and EndExecute() methods?

I don’t remember where I got this but it’s something I’ve used for quite a while now.

public class MyActivity : AsyncTaskCodeActivity<string>
    protected override async Task<string> ExecuteAsync(AsyncCodeActivityContext context, CancellationToken token)
        var result = await SomeAsyncMethod();
        return result.Trim();

Here is the source code, licensed under the MIT license: Open source Task-based Code Activity for use with Workflow Foundation. Licensed under the MIT license. · GitHub

@Bena @fandre You’d asked about this in another question last year. It’s a little late now but hopefully this can be of use to you.

Amendment: This can be consumed in a VB or F# project, but it will either need to be converted or placed in a C# class library in your solution.

1 Like