4. Synchronous
void DemoSync()
{
try // try/catch and using work nicely
{
DoStuff();
DoMoreStuff();
DoEvenMoreStuff();
}
catch (Exception ex)
{
// Handle exception
}
}
5. Asynchronous
async Task<string[]> DemoAsync()
{
try // try/catch and using work nicely
{
var x = await DoStuffAsync();
var y = await DoMoreStuffAsync();
var z = await DoEvenMoreStuffAsync();
return new[] { x, y, z };
}
catch (Exception ex)
{
// Handle exception
}
}
6. Asynchronous
async Task<string[]> DemoAsync()
{
try // try/catch and using work nicely
{
var x = await DoStuffAsync();
var y = await DoMoreStuffAsync();
var z = await DoEvenMoreStuffAsync();
return new[] { x, y, z };
}
catch (Exception ex)
{
// Handle exception
}
}
7. Asynchronous
async Task<string[]> Demo2Async()
{
try // try/catch and using work nicely
{
var taskx = DoStuffAsync();
var x = await taskx;
var y = await DoMoreStuffAsync();
var z = await DoEvenMoreStuffAsync();
return new[] { x, y, z };
}
catch (Exception ex)
{
// Handle exception
}
}
8. Parallel
async Task<string> Demo1Parallel()
{
try // try/catch and using work nicely
{
var task1 = DoStuffAsync();
var task2 = DoMoreStuffAsync();
await task1;
await task2;
return await DoStuffAfterOtherStuffAsync(task1.Result, task2.Result);
}
catch (Exception ex)
{
// Handle exception
}
}
9. Parallel
async Task<string> DemoParallel()
{
try // try/catch and using work nicely
{
var task1 = DoStuffAsync();
var task2 = DoMoreStuffAsync();
await Task.WhenAll(task1, task2);
return await DoStuffAfterOtherStuffAsync(task1.Result, task2.Result);
}
catch (Exception ex)
{
// Handle exception
}
}
13. Distributed - Chaining
async Task<string[]> Run1(DurableOrchestrationContext ctx)
{
try // try/catch and using work nicely
{
var x = await ctx.CallActivityAsync<string>("DoStuffAsync");
var y = await ctx.CallActivityAsync<string>("DoMoreStuffAsync");
var z = await ctx.CallActivityAsync<string>("DoEvenMoreStuffAsync");
return new[] { x, y, z };
}
catch (Exception)
{
// Handle exception
}
}
14. Distributed – Fan-out/Fan-in
public static async Task<string> Run2(DurableOrchestrationContext ctx)
{
try // try/catch and using work nicely
{
var task1 = ctx.CallActivityAsync<string>("DoStuffASync");
var task2 = ctx.CallActivityAsync<string>("DoMoreStuffASync");
await Task.WhenAll(task1, task2);
return await ctx.CallActivityAsync<string>("DoStuffAfterOtherStuffAsync", task1.Result, task2.Result);
}
catch (Exception)
{
// Handle exception
}
}