wpf - 使用 .Net 标准项目在 WPF 应用程序中执行方法
问题描述
我的.Net 标准项目正在使用 .NET 调用WPF 应用程序中的方法reflection
。
我的 .NET 标准项目中的方法调用代码...
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Google.Cast.DesktopV2.exe");
var asm = Assembly.LoadFile(path);
Type t = asm.GetType("Google.Cast.DesktopV2.Utility.PlayMedia");
MethodInfo methodInfo = t.GetMethod("FindMediaPlayer");
var o = Activator.CreateInstance(t);
methodInfo.Invoke(o);
这是我在WPF Application中的方法。
public MediaElement FindMediaPlayer()
{
return ((MainWindow)System.Windows.Application.Current.MainWindow).VideoPlayer;
}
VideoPlayer是我的 XAML 文件中的MediaElement 。我收到错误“调用线程无法访问此对象,因为另一个线程拥有它。” ",无论如何我可以使用反射来实现这一点吗?
解决方案
推荐阅读
- powershell - Powershell列出数组中每个用户的组名
- python-3.x - 通过定义长度和角度在 matplotlib 极坐标图中的箭头
- reactjs - AppData 在 Web 应用程序中的重要性是什么
- if-statement - Prolog if then 带有否定条件
- git - Git - 功能分支之间的冲突 - 如何避免功能分支包含另一个功能分支中的更改
- regex - 在 WordPress 中重写 URL
- sas - Sas 宏 if then else 基于输入参数
- java - 我如何加密/解密 Spring Boot 服务器属性
- javascript - 使用动态变量调用 Cordova 函数
- google-maps-api-3 - 谷歌地图扩大了矩形边界的限制