Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created March 14, 2012 17:16
Show Gist options
  • Save jamesmanning/2037995 to your computer and use it in GitHub Desktop.
Save jamesmanning/2037995 to your computer and use it in GitHub Desktop.
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