Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问C#DLL中的Dispatcher对象?_C#_Dll_Dispatcher - Fatal编程技术网

如何访问C#DLL中的Dispatcher对象?

如何访问C#DLL中的Dispatcher对象?,c#,dll,dispatcher,C#,Dll,Dispatcher,目前我正在WPF中使用以下代码。但现在我需要在DLL中实现同样的功能,而不使用WPF。(没有UI) 有人能建议我怎么做吗?非常感谢您的建议。如果在wpf应用程序中使用dll,并且您包括PresentationFramework程序集,则您应该能够使用System.Windows.application.Current.Dispatcher Alex只要参考WPF框架的3个主要组件,这就没有问题 PresentationCore.dll PresentationFramework.dll Win

目前我正在WPF中使用以下代码。但现在我需要在DLL中实现同样的功能,而不使用WPF。(没有UI)


有人能建议我怎么做吗?非常感谢您的建议。

如果在wpf应用程序中使用dll,并且您包括PresentationFramework程序集,则您应该能够使用
System.Windows.application.Current.Dispatcher


Alex

只要参考WPF框架的3个主要组件,这就没有问题

  • PresentationCore.dll
  • PresentationFramework.dll
  • WindowsBase.dll
这样你就可以使用这个类了

只是一个建议
Dispatcher.Invoke(…)
Application.Current.Dispatcher.Invoke(…)
是将操作分派回表面的两种常用方法。但只要您不使用
Application.Dispatcher
,您就无法确保您的操作将在运行UI元素的同一个Dispatcher中执行。由于您可以在一个
AppDomain
中运行多个Dispatcher,或者如果您的DLL未加载到UI
AppDomain
中,则可能会遇到错误。

所需参考:

PresentationFramework.dll(用于应用程序对象)及其依赖项:

System.Xaml.dll
WindowsBase.dll

您不应该这样做,但不能保证您的dll将在WPF应用程序中运行。改用SynchronizationContext.Current。在构造函数中复制它,以便以后可以调用它的Post()方法。
Dispatcher.CurrentDispatcher.BeginInvoke(new Kepware.ClientAce.OpcDaClient.DaServerMgt.DataChangedEventHandler(DataChanged), DCevHndlrArray);