generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
BackgroundCommandStrategy.cs
38 lines (35 loc) · 1.12 KB
/
BackgroundCommandStrategy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Chinook.DynamicMvvm
{
public static partial class DynamicCommandStrategyExtensions
{
/// <summary>
/// Will execute the command on a background thread.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns><see cref="IDynamicCommandBuilder"/></returns>
public static IDynamicCommandBuilder OnBackgroundThread(this IDynamicCommandBuilder builder)
=> builder.WithStrategy(new BackgroundCommandStrategy());
}
/// <summary>
/// This <see cref="DelegatingCommandStrategy"/> will execute the command on a background thread.
/// </summary>
public class BackgroundCommandStrategy : DelegatingCommandStrategy
{
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundCommandStrategy"/> class.
/// </summary>
public BackgroundCommandStrategy()
{
}
/// <inheritdoc />
public override Task Execute(CancellationToken ct, object parameter, IDynamicCommand command)
{
return Task.Run(() => base.Execute(ct, parameter, command));
}
}
}