private void backgroundWorker2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { while (true) { var code = CourseManager.GetDownloadingCode(); try { if (CourseManager.CourseCodeList.Count > 0) { int i = CourseManager.CourseCodeList.FindIndex(item => item == code) + 1; int progress = (int)(((double)i / (double)CourseManager.CourseCodeList.Count) * 100.0); Console.Write("Downloading "); Console.Write(progress); Console.WriteLine(" / 100"); backgroundWorker1.ReportProgress(progress); } //string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //if (code != "") //{ // int j = alphabet.IndexOf(code[0]) + 1; // backgroundWorker1.ReportProgress((int)(((float)j / (float)alphabet.Length) * 100.0)); //} } catch (Exception ex) { Console.Write("EXXX: "); Console.WriteLine(ex); } label1.Invoke((MethodInvoker) delegate { label1.Text = code; }); } }