예제 #1
0
        /// <summary>
        /// Многопоточно скачивает нужное количество файлов и проверяет каждый на сходство с исходным
        /// </summary>
        /// <param name="filesToDownloadCount"></param>
        /// <returns></returns>
        private void DownloadAndCheck(int filesToDownloadCount)
        {
            var references = GetReferences(filesToDownloadCount);
            var backloader = new BackgroundWorker[references.Count()];
            int index      = 0;

            foreach (var reference in references)
            {
                backloader[index]                     = new BackgroundWorker();
                backloader[index].DoWork             += BackloaderOnDoWork;
                backloader[index].RunWorkerCompleted += (sender, args) =>
                {
                    Monitor.Enter(_resultboxblock);
                    if (args != null)
                    {
                        resultbox.Items.Insert(0, ((Results)args.Result).ToText());
                    }
                    progressBar1.Value += (100 - progressBar1.Value) / Convert.ToInt32(filescount.SelectedItem);
                    Monitor.Exit(_resultboxblock);
                };
                try
                {
                    backloader[index].RunWorkerAsync(reference);
                }
                catch (Exception)
                {
                }
                index++;
            }
            Thread.SpinWait(100);
            while (!Equals(backloader.Count(worker => worker.IsBusy), 0))
            {
            }
        }