static void Main()
    {
      var dm = new DocumentManager();

      ProcessDocuments.StartAsync(dm);

      // Create documents and add them to the DocumentManager
      for (int i = 0; i < 1000; i++)
      {
        Document doc = new Document("Doc " + i.ToString(), "content");
        dm.AddDocument(doc);
        WriteLine("Added document {0}", doc.Title);
        Task.Delay(new Random().Next(20)).Wait();

      }

      ReadLine();

    }
 public static void StartAsync(DocumentManager dm)
 {
   Task.Run(new ProcessDocuments(dm).Run);
 }
 protected ProcessDocuments(DocumentManager dm)
 {
   if (dm == null)
     throw new ArgumentNullException("dm");
   _documentManager = dm;
 }