main
 1using System;
 2using System.Collections.Generic;
 3using System.Linq.Expressions;
 4using gorilla.commons.utility;
 5
 6namespace MoMoney.Service.Infrastructure.Threading
 7{
 8    public class SynchronousCommandProcessor : CommandProcessor
 9    {
10        readonly Queue<Command> queued_commands;
11
12        public SynchronousCommandProcessor()
13        {
14            queued_commands = new Queue<Command>();
15        }
16
17        public void add(Expression<Action> action_to_process)
18        {
19            add(new AnonymousCommand(action_to_process));
20        }
21
22        public void add(Command command_to_process)
23        {
24            queued_commands.Enqueue(command_to_process);
25        }
26
27        public void run()
28        {
29            while (queued_commands.Count > 0) queued_commands.Dequeue().run();
30        }
31
32        public void stop()
33        {
34            queued_commands.Clear();
35        }
36    }
37}