执行第三方代码 [英] Executing third party code

查看:77
本文介绍了执行第三方代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 WPF(Windows 窗体也适用)应用程序,并且对于某些功能,我们依赖于其他团队.我正在寻找一种最佳方式来执行其他团队的功能,而不会影响我们主应用程序的稳定性.

We have a WPF (Windows Forms is also applicable) application and for some functionality we are dependent on other teams. I am looking for a best way to execute the functionaity from other teams without compromising the stability of our main app.

其他团队的功能将包括一些 GUI,可能会调用其他一些服务/数据库等.我们关注的是在 UI 线程上执行其他团队的功能,因为我们不确定他们的编码标准,比如他们是否遵循执行服务时有关后台线程的正确技术.我们有能力根据我们的选择向他们推荐 API 设计.我正在考虑以下两个选项

The other teams functionality will include some GUIs and which may be making calls to some other services/databases etc. And our concern is executing the other teams functionality on UI thread as we are not sure about their coding standards like are they following proper techniques about Background thread when executing services. We have the ability to suggest them on API design to our choice. I am thinking of following two options

  1. API 将异步调用,但会将调度程序作为输入.对传递调度员不太有信心

  1. The API will Async call, but will take dispatcher as input. Not very confident about passing dispatcher around

在服务/GUI 方法中明确提供 API,以便我们可以在后台线程上调用服务,并在完成后将模型传递给 GUI.但这需要我们做更多的工作.

Provide API explicity into service/GUI methods so we can call services on background thread and pass the model to the GUI when completed. But it will involve lot more work on our side.

或者在执行其他团队代码的同时处理我们的应用程序的稳定性时有什么更好的方法来处理.

Or there any better ways to handle when dealing with stabiltiy of our application while executing other teams code.

推荐答案

选项 3:

向他们传递一个名为UIThreadInvoker"的 Action 或一些东西,然后可以将其存储在静态引用中的某处,并在每次需要在 UI 线程上完成某些操作时使用它:

Pass them an Action<Action> called "UIThreadInvoker" or something that then can store somewhere in a static reference and use that every time they need something done on the UI Thread:

你的身边:

//App_Startup or somewhere during initialization
TheirApi.UIThreadInvoker = x => Dispatcher.BeginInvoke(x);

他们的一面:

  public class TheirAPI
   {
       public static Action<Action> UIThreadInvoker {get;set;}

       public void SomeMethod()
       {
           //Pass SomeOtherMethod() to the UIThreadInvoker
           UIThreadInvoker(SomeOtherMethod);
       }

       public void SomeOtherMethod()
       {
           //this will be executed by your dispatcher
       }
   }

这篇关于执行第三方代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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