Why doesn't Clipboard.GetText work?

南楼画角 提交于 2020-01-04 02:56:09

问题


String str = Clipboard.GetText();

throws an exception

An unhandled exception of type 'System.StackOverflowException' occurred in PresentationCore.dll

How do I prevent this problem?


回答1:


You could try:

Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text)

Or take a look here: Clipboard.GetText returns null (empty string)

http://msdn.microsoft.com/es-en/library/system.windows.forms.clipboard.gettext.aspx




回答2:


Look at the accepted answer in this thread:

Link to working code sample

In summary you need to ensure you start or are running in an STAThread with staThread.SetApartmentState(ApartmentState.STA); I also suggest you add a little bit of sleep or wait after join as sometimes the clipboard content is not immediately avaliable when staThread.Join() returns.



来源:https://stackoverflow.com/questions/4648718/why-doesnt-clipboard-gettext-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!