private void Display() { try { Random rand = new Random(); while (true) { for (int i = 0; i < _imgData.GetLength(0); i++) { for (int j = 0; j < _imgData.GetLength(1); j++) { _imgData[i, j] = ((double)(i * width + j) / (double)(width * height)); } } sp.Restart(); var pic = Graphs.DensityGraph(_imgData, ref bitmap, checkBox1.Checked, 1, 0); Invoke(new Action(() => { pictureBox1.Image = pic; textBox1.Text = string.Format("{0} ms", sp.ElapsedMilliseconds); })); } } catch (Exception) { } }