private void Button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); if (!Directory.Exists(TBPath.Text)) { listBox1.Items.Add($"오류: 폴더가 존재하지 않음"); return; } //컨트롤 사용 중단 TBPath.Enabled = false; button1.Enabled = false; listBox1.Items.Add($"작업 초기화"); progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = 100; MyTaskCountFiles counter = new MyTaskCountFiles(this); counter.DirectoryPath = TBPath.Text; counter.TaskStopped += TaskCounterDone; TaskMgr.Tasks.Add(counter); listBox1.Items.Add($"탐색 중: {counter.DirectoryPath}"); counter.Start(); /* * MySampleTask task = new MySampleTask(this); * task.TaskUpdate += OnTaskUpdate; * task.TaskStopped += OnTaskStopped; * task.MAX = progressBar1.Maximum; * TaskMgr.Tasks.Add(task); * * MySampleTaskUpdater updater = new MySampleTaskUpdater(this); * updater.UpdateTarget = task; * TaskMgr.Tasks.Add(updater); * * task.Start(); * updater.Start(); */ }
void TaskCounterDone(object sender) { MyTaskCountFiles counter = sender as MyTaskCountFiles; TaskMgr.Tasks.Remove(counter); string[] files = counter.Files; progressBar1.Maximum = files.Count(); int processor = Environment.ProcessorCount; if (processor < 1) { listBox1.Items.Add($"오류: 이 장치에 가용 가능한 논리 프로세서가 없음"); EntireTaskFinished(); return; } listBox1.Items.Add($"탐색된 파일 {progressBar1.Maximum} 개에 대한 일괄 처리 개시"); listBox1.Items.Add($"일괄 처리에 프로세서 {processor}개 가용"); MaxProcessor = processor; WorkingThread = processor; Converters = new MyTaskConvertImageFile[processor]; listBox1.Items.Add($"처리 중: {progressBar1.Value}/{progressBar1.Maximum}"); Queue <string>[] subfiles = new Queue <string> [processor]; for (int i = 0; i < MaxProcessor; i++) { subfiles[i] = new Queue <string>(); } { int imax = progressBar1.Maximum; int splt = 0; for (int i = 0; i < imax; i++) { subfiles[splt].Enqueue(files[i]); splt++; if (splt >= MaxProcessor) { splt = 0; } } } for (int i = 0; i < MaxProcessor; i++) { MyTaskConvertImageFile converter = new MyTaskConvertImageFile(this); converter.Files = subfiles[i].ToArray(); converter.TaskUpdate += TaskConverterUpdate; converter.TaskStopped += TaskConverterDone; TaskMgr.Tasks.Add(converter); Converters[i] = converter; MyTaskUpdater updater = new MyTaskUpdater(this); updater.UpdateTarget = converter; updater.UpdateDelay = 500 + 25 * i; converter.Start(); updater.Start(); } }