Fix STAThreadAttribute issue

This commit is contained in:
Namhyeon Go 2024-09-04 16:18:05 +09:00
parent 85ba0c14be
commit bab0a3bba2

View File

@ -9,6 +9,7 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text; using System.Text;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Tesseract; using Tesseract;
using WelsonJS.Service; using WelsonJS.Service;
@ -357,15 +358,20 @@ public class ScreenMatch
// if use Clipboard // if use Clipboard
if (isUseSampleClipboard) if (isUseSampleClipboard)
{ {
try Thread th = new Thread(new ThreadStart(() =>
{ {
Clipboard.SetImage(croppedBitmap); try
parent.Log($"Copied to the clipboard"); {
} Clipboard.SetImage(croppedBitmap);
catch (Exception ex) parent.Log($"Copied the image to Clipboard");
{ }
parent.Log($"Error in Clipboard: {ex.Message}"); catch (Exception ex)
} {
parent.Log($"Error in Clipboard: {ex.Message}");
}
}));
th.SetApartmentState(ApartmentState.STA);
th.Start();
} }
// if use OCR // if use OCR