private void button1_Click(object sender, EventArgs e) { picImage.Refresh(); var watch = System.Diagnostics.Stopwatch.StartNew(); Random objRandom = new Random(); dataSetList = new List <double[]>(); for (int i = 0; i < int.Parse(textBox5.Text); i++) { // khoi tao mang 1 chieu point voi 2 phan tu ung voi toa do x va y double[] point = new double[2]; for (int j = 0; j < 2; j++) { if (j == 0) // neu j==0 la x { // tao ngau nhien toa do x theo chieu dai cua picturebox point[j] = Misc.taoDiemNgauNhien(objRandom, 0, 500); } else // nguoc lai la y { // tao ngau nhien toa do y theo chieu cao cua picturebox point[j] = Misc.taoDiemNgauNhien(objRandom, 0, 500); } } // them diem vua tao vao list diem dataSetList.Add(point); } // goi ham khoi tao 2 tham so o class Kmeans voi 2 tham so lan luot la so cum, va khoang cach objKMeans = new KMeans((int)numericUpDown2.Value, new TinhKhoangCach(), int.Parse(textBox4.Text)); objBackgroundWorker = new BackgroundWorker(); objBackgroundWorker.WorkerReportsProgress = true; objBackgroundWorker.DoWork += ObjBackgroundWorker_DoWork; objBackgroundWorker.RunWorkerCompleted += ObjBackgroundWorker_RunWorkerCompleted; objBackgroundWorker.ProgressChanged += ObjBackgroundWorker_ProgressChanged; objBackgroundWorker.RunWorkerAsync(dataSetList.ToArray()); watch.Stop(); var elapsedMs = watch.Elapsed.TotalSeconds; //MessageBox.Show(elapsedMs.ToString()); textBox1.Text = elapsedMs.ToString(); }