wpf 将 SignalR 用于桌面应用程序是否正确?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31261987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:15:02  来源:igfitidea点击:

Is it correct to use SignalR for desktop applications?

c#.netwpfwinformssignalr

提问by Se?kin Durgay

Is SignalR suitable for windows desktop applications (winforms/wpf)?

SignalR 是否适合 Windows 桌面应用程序 (winforms/wpf)?

What are the advantages and disadvantages using SignalR with windows desktop applications?

将 SignalR 与 Windows 桌面应用程序一起使用的优点和缺点是什么?

Are there any performance considerations?

是否有任何性能考虑?

I want to make real-time connections between server and a lot of clients. The connections will be constant.

我想在服务器和许多客户端之间建立实时连接。连接将是恒定的。

采纳答案by Patrick Hofman

Is SignalR suitable for windows desktop applications (winforms/wpf)?

SignalR 是否适合 Windows 桌面应用程序 (winforms/wpf)?

The answer from signalr.netis:

来自signalr.net的答案是:

SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application.

SignalR 可用于向 ASP.NET 应用程序添加任何类型的“实时”Web 功能。

(As stated correctly by others it can be self-hosted, so no need for IIS)

(正如其他人正确说明的那样,它可以自托管,因此不需要 IIS

So the answer seems to be no. It is a server side API. But today is your lucky day, since the download of SignalR doesn't only reveal the server side API, but also a client side API called Microsoft.AspNet.SignalR.Client45to use in your application. It works for WPF, WF or even console applications.

所以答案似乎是否定的。它是一个服务器端 API。但今天是您的幸运日,因为 SignalR 的下载不仅会显示服务器端 API,还会显示调用Microsoft.AspNet.SignalR.Client45以在您的应用程序中使用的客户端 API 。它适用于 WPF、WF 甚至控制台应用程序。

And even if it didn't, SignalR is just a wrapper around the WebSockets protocol, which is part of the HTTP protocol, which can be used on virtually any platform. The download also contains a sample for iOS and Xamarin for example.

即使没有,SignalR 也只是WebSockets 协议的包装器,它是 HTTP 协议的一部分,几乎可以在任何平台上使用。例如,下载还包含一个适用于 iOS 和 Xamarin 的示例。

What are the advantages and disadvantages using SignalR with windows desktop applications?

将 SignalR 与 Windows 桌面应用程序一起使用的优点和缺点是什么?

To have real-time notifications from and to the server.

接收来自和发送到服务器的实时通知。

Is there any performance problems?

有没有性能问题?

That is a hard question to answer, since there is no reference point. Compared to what the performance is good or bad? Generally spoken, I don't think you have to worry to much about that. The API itself is fast, and it may prevent slow pull-requests you need to do else.

这是一个很难回答的问题,因为没有参考点。相比之下,性能好还是坏呢?一般来说,我认为你不必担心太多。API 本身很快,它可以防止您需要做其他事情的缓慢拉取请求。

回答by Liero

It is absolutelly correct to consume SinglarR hub in any client application, WPF, windows phone, UWP, iOS, Android, including HTML. Microsoft has created client libraries on many platforms.

在任何客户端应用程序、WPF、Windows Phone、UWP、iOS、Android(包括 HTML)中使用 SinglarR hub 是绝对正确的。Microsoft 在许多平台上创建了客户端库。

When it comes to hosting SignalR, then you can definitelly host you SingalR server (hub) in WPF application, but you need a reason:

当涉及到托管 SignalR 时,您绝对可以在 WPF 应用程序中托管您的 SingalR 服务器(集线器),但您需要一个理由:

The reason may be:

原因可能是:

  • IIS is not available
  • You don't know in advance where the APP will be used. You just need to run an app, that will notify other apps
  • Performance - IIS adds some performance overhead.
  • IIS 不可用
  • 您事先不知道该 APP 将在哪里使用。您只需要运行一个应用程序,它就会通知其他应用程序
  • 性能 - IIS 增加了一些性能开销。

By the way, SignalR and OWIN has been an inspiration for the new ASP.NET 5. You can now host your ASP.NET apps in WPF, console application or windows service app without IIS, or even on Linux.

顺便说一下,SignalR 和 OWIN 是新 ASP.NET 5 的灵感来源。您现在可以在 WPF、控制台应用程序或 Windows 服务应用程序中托管您的 ASP.NET 应用程序,而无需 IIS,甚至在 Linux 上。

http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host

http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host

回答by DrKoch

In a setup with a server and many clients: If you need "push" notifications from the server to some clients then SignalR is good to use.

在具有服务器和许多客户端的设置中:如果您需要从服务器向某些客户端“推送”通知,那么 SignalR 非常适合使用。

I do so with WPF clients.

我对 WPF 客户端这样做。

回答by Thanasis Ioannidis

When you build a website with signalr functionality you have a signalR server, where the site is hosted and a signalr client, the javascript client that runs in the web browser that browses the site.

当您构建具有信号器功能的网站时,您将拥有一个用于托管站点的信号服务器服务器和一个信号器客户端,即在浏览网站的 Web 浏览器中运行的 javascript 客户端。

From years immemorable, web browsers were (and still are)... well,... desktop applications...

自古以来,Web 浏览器曾经(现在仍然是)……嗯,……桌面应用程序……

So you have desktop applications (the web broswer) that use SignalR to connect to a web site (the web server).

因此,您拥有使用 SignalR 连接到网站(Web 服务器)的桌面应用程序(Web 浏览器)。

So, not only is it correct to use signalR for desktop applications, but this is what it is meant for. I really don't know what would be the use of signalR if it wasn't to be used in a desktop application at some point, because, frankly, a user sits in front of a desktop (or a smart device), and doesn't exist "in the cloud" (unless you are Neo from Matrix). With signalR you have "real-time" reactions from the server presented in your desktop environment (a web browser or another desktop application, for instance an application that controls the lights in your home, or prints something in your printer).

因此,将 signalR 用于桌面应用程序不仅是正确的,而且这就是它的意义所在。我真的不知道如果不是在某个时候在桌面应用程序中使用 signalR 会有什么用,因为坦率地说,用户坐在桌面(或智能设备)前面,并且不不存在于“云端”(除非你是来自 Matrix 的 Neo)。使用 signalR,您可以从桌面环境中呈现的服务器(Web 浏览器或其他桌面应用程序,例如控制家中的灯光或在打印机中打印某些内容的应用程序)中获得“实时”反应。