“Current thread must be set to single thread apartment (STA)” error in copy string to clipboard
问题 I have tried code from How to copy data to clipboard in C#: Clipboard.SetText("Test!"); And I get this error: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. How can I fix it? 回答1: Make sure thread that runs the code is marked with [STAThread] attribute. For WinForm and console based apps it is generally Main method Put [STAThread] above your main method: [STAThread] static void