TPL - Log data Async

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

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...