private void cmBones_Click(object sender, EventArgs e) { var bw = new BackgroundWorker(); bw.DoWork += (a, b) => { Data dat = new Data(); try { Bitmap img = (Bitmap)b.Argument; var detector = new BoneDetector(img); var ld = new LineDetector(); image = ld.Apply(detector.Apply()); picture.Image = image; if (ld.Lines.Count == 2) { var data2 = image.Lock(); var um2 = new UnmanagedImage(data2); var crossed = ld.Lines[0].CrossPoint(ld.Lines[1]); Drawing.Rectangle(um2, new Rectangle(crossed.X - 10, crossed.Y - 10, 20, 20), Color.Green); image.Unlock(data2); } dat.image = image; dat.message = ld.GetInfo(); } catch (Exception ex) { dat.image = null; dat.message = ex.GetError(); } b.Result = dat; }; bw.RunWorkerCompleted += (a, b) => { Data dat = (Data)b.Result; picture.Image = dat.image; bonesInfo = dat.message; blockInterface(false); progress.Visible = false; status.Text = "Przetwarzanie zakończone"; MessageBox.Show(dat.message); }; if (image == null) { openFile(); } blockInterface(true); progress.Enabled = true; progress.Style = ProgressBarStyle.Marquee; progress.Visible = true; status.Text = "Przetwarzanie rozpoczęte..."; bw.RunWorkerAsync(image); }