您只能从STA线程访问剪贴板。Rick Brewster在Paint.NET中通过对常规Edit-> Paste命令进行一些重构来解决此问题。
码:
IDataObject idat = null;
Exception threadEx = null;
Thread staThread = new Thread(
delegate ()
{
try
{
idat = Clipboard.GetDataObject();
}
catch (Exception ex)
{
threadEx = ex;
}
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
// at this point either you have clipboard data or an exception
代码来自里克。http://forums.getpaint.net/index.php?/topic/13712-/page__view__findpost__p__226140