diff --git a/Greenshot/Destinations/PickerDestination.cs b/Greenshot/Destinations/PickerDestination.cs index 7342eecc0..4c699c37f 100644 --- a/Greenshot/Destinations/PickerDestination.cs +++ b/Greenshot/Destinations/PickerDestination.cs @@ -67,11 +67,10 @@ namespace Greenshot.Destinations { public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { ContextMenuStrip menu = new ContextMenuStrip(); - menu.Closed += delegate(object source, ToolStripDropDownClosedEventArgs eventArgs) { - // Dispose surface when no item was clicked, else the dispose should be made there! - if (eventArgs.CloseReason != ToolStripDropDownCloseReason.ItemClicked) { - LOG.DebugFormat("Disposing as no item was clicked, reason: {0}", eventArgs.CloseReason); - surface.Dispose(); + menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) { + LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason); + if (eventArgs.CloseReason != ToolStripDropDownCloseReason.ItemClicked && eventArgs.CloseReason != ToolStripDropDownCloseReason.CloseCalled) { + eventArgs.Cancel = true; } }; @@ -83,25 +82,27 @@ namespace Greenshot.Destinations { continue; } // Fix foreach loop variable for the delegate - ToolStripMenuItem item = destination.GetMenuItem(delegate(object sender, EventArgs e) { - ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; - if (toolStripMenuItem == null) { - return; + ToolStripMenuItem item = destination.GetMenuItem( + delegate(object sender, EventArgs e) { + ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; + if (toolStripMenuItem == null) { + return; + } + IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag; + if (clickedDestination == null) { + return; + } + bool result = clickedDestination.ExportCapture(surface, captureDetails); + // TODO: Find some better way to detect that we exported to the editor + if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) { + LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result); + // Cleanup surface + surface.Dispose(); + } + // Make sure the menu is closed + menu.Close(); } - IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag; - if (clickedDestination == null) { - return; - } - bool result = clickedDestination.ExportCapture(surface, captureDetails); - // TODO: Find some better way to detect that we exported to the editor - if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) { - LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result); - // Cleanup surface - surface.Dispose(); - } - // Make sure the menu is closed - menu.Close(); - }); + ); if (item != null) { menu.Items.Add(item); } @@ -112,6 +113,7 @@ namespace Greenshot.Destinations { closeItem.Click += delegate { // This menu entry is the close itself, we can dispose the surface menu.Close(); + // Dispose as the close is clicked surface.Dispose(); }; menu.Items.Add(closeItem); diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 2648b1124..c09d80f78 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -1111,6 +1111,7 @@ namespace Greenshot { LOG.Debug("BackgroundWorkerTimerTick checking for update"); // Start update check in the background Thread backgroundTask = new Thread (new ThreadStart(UpdateHelper.CheckAndAskForUpdate)); + backgroundTask.Name = "Update check"; backgroundTask.IsBackground = true; backgroundTask.Start(); } diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 0fe1f61a3..32b5b1446 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -351,6 +351,7 @@ namespace Greenshot.Helpers { windows = WindowDetails.SortByZOrder(IntPtr.Zero, windows); } }); + getWindowDetailsThread.Name = "Retrieve window details"; getWindowDetailsThread.IsBackground = true; getWindowDetailsThread.Start(); } diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs index 457105fc3..1831509a3 100644 --- a/Greenshot/Helpers/MailHelper.cs +++ b/Greenshot/Helpers/MailHelper.cs @@ -202,7 +202,7 @@ namespace Greenshot.Helpers { // Create the mail message in an STA thread Thread t = new Thread(new ThreadStart(_ShowMail)); t.IsBackground = true; - t.Name = Application.ProductName; + t.Name = "Create MAPI mail"; t.SetApartmentState(ApartmentState.STA); t.Start(); diff --git a/Greenshot/Helpers/ScreenCaptureHelper.cs b/Greenshot/Helpers/ScreenCaptureHelper.cs index 325dc2ab8..f498e8945 100644 --- a/Greenshot/Helpers/ScreenCaptureHelper.cs +++ b/Greenshot/Helpers/ScreenCaptureHelper.cs @@ -175,6 +175,7 @@ namespace Greenshot.Helpers { // Start update check in the background backgroundTask = new Thread (new ThreadStart(CaptureFrame)); backgroundTask.IsBackground = true; + backgroundTask.Name = "Capture video"; backgroundTask.Start(); return true; } else { diff --git a/GreenshotConfluencePlugin/Confluence.cs b/GreenshotConfluencePlugin/Confluence.cs index c7e5cdf9e..99e4c1001 100644 --- a/GreenshotConfluencePlugin/Confluence.cs +++ b/GreenshotConfluencePlugin/Confluence.cs @@ -25,6 +25,7 @@ using System.Windows.Forms; using GreenshotConfluencePlugin; using GreenshotPlugin.Core; using IniFile; +using GreenshotConfluencePlugin.confluence; /// /// For details see the Confluence API site diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index 2ad67163c..5307f0d2d 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -97,6 +97,7 @@ namespace ExternalCommand { Thread commandThread = new Thread (delegate() { CallExternalCommand(presetCommand, fullPath); }); + commandThread.Name = "Running " + presetCommand; commandThread.IsBackground = true; commandThread.Start(); surface.SendMessageEvent(this, SurfaceMessageTyp.Info, host.CoreLanguage.GetFormattedString("exported_to", Description)); diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs index f4a54b6c7..5d03c1956 100644 --- a/GreenshotImgurPlugin/ImgurPlugin.cs +++ b/GreenshotImgurPlugin/ImgurPlugin.cs @@ -97,6 +97,7 @@ namespace GreenshotImgurPlugin { // retrieve history in the background Thread backgroundTask = new Thread (new ThreadStart(CheckHistory)); + backgroundTask.Name = "Imgur History"; backgroundTask.IsBackground = true; backgroundTask.SetApartmentState(ApartmentState.STA); backgroundTask.Start(); diff --git a/GreenshotNetworkImportPlugin/HTTPReceiver.cs b/GreenshotNetworkImportPlugin/HTTPReceiver.cs index 1079c013d..514fe0b6b 100644 --- a/GreenshotNetworkImportPlugin/HTTPReceiver.cs +++ b/GreenshotNetworkImportPlugin/HTTPReceiver.cs @@ -42,6 +42,7 @@ namespace GreenshotNetworkImportPlugin { } public void StartListening() { Thread serverThread = new Thread(Listen); + serverThread.Name = "HTTP Receiver"; serverThread.SetApartmentState(ApartmentState.STA); serverThread.Start(); } @@ -92,7 +93,9 @@ namespace GreenshotNetworkImportPlugin { } try { HttpListenerContext context = listener.EndGetContext(result); - new Thread(ProcessRequest).Start(context); + Thread requestThread = new Thread(ProcessRequest); + requestThread.Name = "Process Request"; + requestThread.Start(context); } catch (HttpListenerException httpE) { LOG.Error(httpE); } diff --git a/GreenshotPlugin/Controls/BackgroundForm.cs b/GreenshotPlugin/Controls/BackgroundForm.cs index 98c0bae63..7e161407f 100644 --- a/GreenshotPlugin/Controls/BackgroundForm.cs +++ b/GreenshotPlugin/Controls/BackgroundForm.cs @@ -38,6 +38,7 @@ namespace GreenshotPlugin.Controls { BackgroundForm backgroundForm = new BackgroundForm(title, text); // Show form in background thread Thread backgroundTask = new Thread (new ThreadStart(backgroundForm.BackgroundShowDialog)); + backgroundForm.Name = "Background form"; backgroundTask.IsBackground = true; backgroundTask.SetApartmentState(ApartmentState.STA); backgroundTask.Start();