Scenario:
Store log in parallel and async way.Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | static void Main(string[] args) { var q = new BlockingCollection<ILog>(); Task.Factory.StartNew( () => { foreach (var log in q.GetConsumingEnumerable()) { List<Action<ILog>> handlers; if (_handlers.TryGetValue(log.Type, out handlers)) { Task.Factory.StartNew( () => Parallel.ForEach(handlers, handler => { handler(log); })); } } }); Console.ReadLine(); } |
No comments:
Post a Comment