-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calls requiring STA threads don't work #26
Comments
Do you have a minimal LINQPad script that you can share (even if via LINQPad's Instant Share feature) along with steps that can help to reproduce the problem? |
Uses System.Windows.Clipboard
The above compiles but gives the error on running: This was the solution I used before:
But compiling gives
|
@rekna1 Thanks for sharing that example. I managed the reproduce the issue. Meanwhile, a workaround would be to explicitly configure a thread for STA and run your code under that, like this: void Run()
{
var text = Clipboard.GetText();
Console.WriteLine(text);
}
void Main()
{
var t = new Thread(Run);
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
} I've also shared the above query that you can download and try in LINQPad as well as run with LINQPadless. |
Oké, finally had a chance to try your workaround and that works great ! |
Good to know and thanks for taking the time to drop in a line to let me know. |
I have a script that need to access the clipboard. After compiling with lpless when I try to run executable it complains that to access clipboard it need STAthread. When I add this attribute to the linqpad script I get an error from compiler that it finds multiple entry points main and I need to specify main entry point. Any idea ?
The text was updated successfully, but these errors were encountered: