[UWP]从多个(核心)Windows访问剪贴板 [英] [UWP]Accessing Clipboard from Multiple (Core) Windows

查看:149
本文介绍了[UWP]从多个(核心)Windows访问剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的UWP应用程序可以有多个窗口,我想了解从这些不同窗口访问Clipboard对象的语义。 


剪贴板文档说明如下 


https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.datatransfer.clipboard


>>


 此类不敏捷,这意味着您需要考虑其线程模型和编组行为。有关详细信息,请参阅  线程
和Marshaling(C ++ / CX)
和  在多线程环境(.NET)中使用Windows运行时对象

解决方案


文档说 


您只能在调用应用程序位于$ b时访问剪贴板$ b 专注于UI线程
(例如,当它是< CoreWindow  
有效)。


  ;这意味着应用程序应该有Foucused UI线程,它是无关紧要的是主窗口线程还是其他Window线程。在您执行代码的情况下,您已经有了焦点线程。


Hi,

My UWP app can have multiple windows and I want to understand the semantics around accessing Clipboard object from these different windows. 

Clipboard documentation says the following 

https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.datatransfer.clipboard

>>

 This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX)and Using Windows Runtime objects in a multithreaded environment (.NET).

解决方案

Hi,

The documentation say  

You can only access the clipboard when the calling application is in focus on the UI thread (e.g., when it's CoreWindow is active).

 That mean that application should have Foucused UI thread it is doesn't matter does it is Main Window thread or an other Window thread. In your case when you execute your code you already have focused thread.


这篇关于[UWP]从多个(核心)Windows访问剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆