Created
March 14, 2012 17:16
-
-
Save jamesmanning/2037995 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using log4net; | |
using log4net.Config; | |
namespace ItsBigItsHeavyItsWood | |
{ | |
class Program | |
{ | |
private static readonly ILog s_logger = LogManager.GetLogger("Logger"); | |
private static readonly Random s_random = new Random(); | |
static void Main() | |
{ | |
BasicConfigurator.Configure(); | |
var items = new[] | |
{ | |
"a", | |
"b", | |
"c", | |
"d", | |
"e", | |
"f", | |
}; | |
s_logger.Info("starting all tasks"); | |
var tasks = items.Select(Process).ToArray(); | |
s_logger.Info("started all tasks"); | |
Task.WaitAll(tasks); | |
} | |
private static async Task Process(string item) | |
{ | |
using (NDC.Push(String.Format("[item {0}]", item))) | |
{ | |
s_logger.InfoFormat("starting stuff with item {0}", item); | |
await Task.Delay(TimeSpan.FromSeconds(s_random.Next(30))); | |
s_logger.InfoFormat("doing more stuff with item {0}", item); | |
await Task.Delay(TimeSpan.FromSeconds(s_random.Next(30))); | |
s_logger.InfoFormat("done with item {0}", item); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment