git-svn-id: https://abrams/svn/LanSpider-repo@22 16f2e333-51b0-4855-8c5a-a66b7be24171
[LanSpider.git] / src / LanSpider / Multithreading / Consumer.cs
blobc127dfa5ed2a9fad3226cd866d5db22c7bc4eacc
1 using System;
2 using System.Collections.Generic;
4 namespace LanSpider.Multithreading
6 /// <summary>
7 /// Consumes work items produced by WorkManager.
8 /// </summary>
9 public class Consumer< TResult >
11 private List<TResult> _results;
12 private readonly object _resultsLock = new object();
14 public IEnumerable<TResult> Results
16 get
18 if ( _results == null )
20 throw new InvalidOperationException( "Cannot return results before work was preformed" );
23 return _results;
27 public void Consume( TResult result )
29 lock ( _resultsLock )
31 if ( _results == null )
33 _results = new List<TResult>();
36 _results.Add( result );