summaryrefslogtreecommitdiff
path: root/lib/infrastructure/threading/SynchronizedCommand.cs
blob: fb789059d40babfb329c7b94e07b9d24825aaa13 (plain)
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
using System;
using System.Threading;
using gorilla.utility;

namespace gorilla.infrastructure.threading
{
    public interface ISynchronizedCommand : Command<Action>, Command<Command> {}

    public class SynchronizedCommand : ISynchronizedCommand
    {
        readonly SynchronizationContext context;

        public SynchronizedCommand(SynchronizationContext context)
        {
            this.context = context;
        }

        public void run(Action item)
        {
            context.Post(x => item(), new object());
        }

        public void run(Command item)
        {
            run(item.run);
        }
    }
}