main
 1using gorilla.commons.Utility;
 2
 3namespace gorilla.commons.infrastructure.threading
 4{
 5    public interface IBackgroundThread : DisposableCommand {}
 6
 7    public class BackgroundThread : IBackgroundThread
 8    {
 9        readonly IWorkerThread worker_thread;
10
11        public BackgroundThread(DisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread()) {}
12
13        public BackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread)
14        {
15            this.worker_thread = worker_thread;
16            worker_thread.DoWork += (sender, e) => command_to_execute.run();
17            worker_thread.Disposed += (sender, e) => command_to_execute.Dispose();
18        }
19
20        public void run()
21        {
22            worker_thread.begin();
23        }
24
25        public void Dispose()
26        {
27            worker_thread.Dispose();
28        }
29    }
30}