fixed #6731: Run PinToScreenForm inside separate thread

This commit is contained in:
Jaex 2023-01-31 09:07:23 +03:00
parent 744f844f9c
commit cab9a5a57f
2 changed files with 25 additions and 3 deletions

View file

@ -1319,8 +1319,7 @@ public static void PinToScreen(Image image, Point? location = null)
PinToScreenOptions options = new PinToScreenOptions();
options.BackgroundColor = ShareXResources.Theme.LightBackgroundColor;
PinToScreenForm form = new PinToScreenForm(image, options, location);
form.Show();
PinToScreenForm.PinToScreenAsync(image, options, location);
}
}

View file

@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;
namespace ShareX
@ -128,7 +129,7 @@ private PinToScreenForm(PinToScreenOptions options)
loaded = true;
}
public PinToScreenForm(Image image, PinToScreenOptions options, Point? location = null) : this(options)
private PinToScreenForm(Image image, PinToScreenOptions options, Point? location = null) : this(options)
{
Image = image;
AutoSizeForm();
@ -144,6 +145,28 @@ public PinToScreenForm(Image image, PinToScreenOptions options, Point? location
}
}
public static void PinToScreenAsync(Image image, PinToScreenOptions options = null, Point? location = null)
{
if (image != null)
{
if (options == null)
{
options = new PinToScreenOptions();
}
Thread thread = new Thread(() =>
{
using (PinToScreenForm form = new PinToScreenForm(image, options, location))
{
form.ShowDialog();
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
protected override void Dispose(bool disposing)
{
if (disposing)