async void DetectButton_Click(object sender, EventArgs e) { // filter the background filterPictureBox.Image = await Task.Run(() => autoCrop.FilterBackGround(autoCrop.ImageData as Bitmap)); // detect the edges of the cropping area. var rectangle = autoCrop.DetectEdges(filterPictureBox.Image as Bitmap); // show the result if we have one if (!rectangle.IsEmpty) { resultPictureBox.Image = autoCrop.TryCrop(autoCrop.ImageData as Bitmap, rectangle); saveMenuItem.Enabled = true; } infoLabel.Text = $"{rectangle.Width} x {rectangle.Height}"; }