source: trunk/CrypPlugins/MD5Collider/Algorithm/ColliderWorkerAdapter.cs @ 1355

Last change on this file since 1355 was 1355, checked in by pretzsch, 12 years ago

+ MD5Collider: Added multithreaded execution

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ComponentModel;
6
7namespace Cryptool.Plugins.MD5Collider.Algorithm
8{
9    class ColliderWorkerAdapter<T> where T : IMD5ColliderAlgorithm, new()
10    {
11        private IMD5ColliderAlgorithm wrappedCollider;
12
13        private MultiThreadedMD5Collider<T> multiThreadedCollider;
14
15        private BackgroundWorker worker;
16
17        public bool IsStarted { get { return worker.IsBusy; } }
18
19        public ColliderWorkerAdapter(MultiThreadedMD5Collider<T> multiThreadedCollider, IMD5ColliderAlgorithm wrappedCollider)
20        {
21            this.multiThreadedCollider = multiThreadedCollider;
22            this.wrappedCollider = wrappedCollider;
23
24            worker = new BackgroundWorker();
25            worker.DoWork += DoWork;
26            worker.RunWorkerCompleted += RunWorkerCompleted;
27        }
28
29        private void DoWork(object sender, DoWorkEventArgs e)
30        {
31            wrappedCollider.FindCollision();
32        }
33
34        private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
35        {
36            multiThreadedCollider.SignalWorkIsFinished(wrappedCollider);
37        }
38
39        public void StartWork()
40        {
41            worker.RunWorkerAsync();
42        }
43    }
44}
Note: See TracBrowser for help on using the repository browser.