Example #1
0
        /// <summary>
        /// Constructor of the ColorCalculater
        /// </summary>
        /// <param name="listView_overview">The ListView in which progress will be written</param>
        /// <param name="fileManager">The FileManager from which tasks will be gotten</param>
        public ColorCalculator(ListView listView_overview, FileManager fileManager, int core, object taskLock)
        {
            //Set the FileManager
            this.fileManager = fileManager;
            //Set the ListView
            this.listView_overview = listView_overview;
            //Set the taskLock
            this.taskLock = taskLock;

            //Enable progress reporting
            WorkerReportsProgress = true;

            Monitor.Enter(taskLock);
            try
            {
                if (fileManager.FilesWaiting > 0)
                {
                    task = fileManager.getTask();
                }
            }
            finally { Monitor.Exit(taskLock); }

            ////Support Cancellation
            //WorkerSupportsCancellation = true;
        }
Example #2
0
        /// <summary>
        /// The constructor from the MainForm class
        /// </summary>
        public MainForm()
        {
            //Initialize the FileManager
            fileManager = new FileManager();
            //Initialize the ThreadManager
            threadManager = new ThreadManager();
            //Add a AllThreadsDone listener to the ThreadManager
            threadManager.allThreadsDone += new ThreadManager.AllThreadsDone(threadsDone);

            //Initialize the form
            InitializeComponent();

            ////Prioritize the WinForm thread above the worker threads
            //Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
        }
Example #3
0
        public void startThreads(FileManager fileManager, ListView listView_overview, int numberOfThreads, int numberOfCores)
        {
            //Give the workers array a length
            workers = new ColorCalculator[numberOfThreads];

            //Set threads running to true
            threadsRunning = true;

            //For every worker in workers
            for (int i = 0; i < workers.Length; i++)
            {
                //Fill the workers array with ColorCalculators
                workers[i] = new ColorCalculator(listView_overview, fileManager, i%numberOfCores, taskLock);
                //Add a listener that's called when the thread is done working
                workers[i].Done += new ColorCalculator.DoneHandler(threadFinished);

                //Start the worker
                workers[i].RunWorkerAsync();
                //Iterate the number of running workers
                tasksRunning++;
            }
        }