简体   繁体   English

任务,CodedUI和剪贴板错误

[英]Task, CodedUI, and Clipboard errors

I am updating a CodedUI test program. 我正在更新CodedUI测试程序。 Part of the update I have been working on is threading the test so that I can cancel the test, when necessary, without needing to kill the test program. 我一直在进行的部分更新工作是对测试进行线程化,以便在必要时可以取消测试,而无需终止测试程序。 The Task I create works fine until the CodedUI test copies data to the Clipboard then tries to retrieve that so it can dump it to a database. 我创建的任务运行良好,直到CodedUI测试将数据复制到剪贴板,然后尝试检索该数据,以便将其转储到数据库。 Without the task, this works with no issues, but with the task, Clipboard.GetData(DataFormats.Text) returns null. 如果没有任务,则不会有任何问题,但是对于任务, Clipboard.GetData(DataFormats.Text)将返回null。

Because Keyboard.SendKeys is used before the Clipboard request, I tried CodedUI Test: Keyboard.SendKeys not working to see if that would help, but it did not. 因为在剪贴板请求之前使用了Keyboard.SendKeys ,所以我尝试了CodedUI测试:Keyboard.SendKeys无法正常工作 ,看是否有帮助,但没有帮助。

Getting data off the Clipboard inside a BackgroundWorker solved the issue. 从BackgroundWorker内部的剪贴板中获取数据解决了该问题。 Though nothing threw errors relating to the Thread Apartment State, setting it to STA makes things work. 尽管没有任何东西引发与线程单元状态有关的错误,但将其设置为STA可以使事情正常进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM