简体   繁体   English

请求排队vb.net

[英]Request queuing vb.net

We currently have third-party software that we use to extract information from. 当前,我们拥有用于提取信息的第三方软件。

We use their SDK to send and receive request and noted that the request aren't always accurate. 我们使用他们的SDK发送和接收请求,并注意到请求并不总是准确的。 After troubleshooting and reading (not well documented) documentation we realised that the SDK can only receive and send one request at a time. 经过故障排除和阅读(没有充分记录的文档)文档后,我们意识到SDK一次只能接收和发送一个请求。

This causes a issue for us as we are using an ASP.Net web application to access the SDK which means that we have multiple clients that access the SDK at the same time and send multiple request. 当我们使用ASP.Net Web应用程序访问SDK时,这给我们带来了问题,这意味着我们有多个客户端可以同时访问SDK并发送多个请求。 What the SDK does is if it get a new request while busy with a current request it discards the current request and continues with the new request. SDK的作用是,如果在忙于当前请求时收到新请求,它将丢弃当前请求并继续执行新请求。

I would like to find out what would be the best way of creating a queuing system for the requests. 我想找出什么是为请求创建排队系统的最佳方法。

I was thinking of creating a WCF service and set the instancecontexctmode to single so that there is only one instance of the service running. 我当时正在考虑创建WCF服务,并将instancecontexctmode设置为single,以便仅运行该服务的一个实例。 Then setting the ThreadPool max threads to 1 and using it to queue the functions so that there is only one active call to the SDK at a time. 然后将ThreadPool最大线程数设置为1,并使用它来对函数进行排队,以便一次仅对SDK进行一次活动调用。 Although I do not know much about ThreadPool queuing the solution should work. 尽管我对ThreadPool排队了解不多,但该解决方案应该可以工作。

Here is what I have in mind 这就是我的想法

Public Sub Sub1(var As String) 
    'Do work
    ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Function1), "Text")
End Sub

Public Function Function1(var As String) As DataTable
    'Do Work
    Return DataTable
End Function

Sub New()
    ThreadPool.SetMaxThreads(1, 1)
End Sub

How would I create the queueing using ThreadPool or is there another way to accomplish the same result? 我将如何使用ThreadPool创建队列,或者还有另一种方法可以实现相同的结果?

Will the web application wait for a response from the service? Web应用程序将等待服务的响应吗?

Update 1 更新1

I found another way while fiddling with some code 我在摆弄一些代码时找到了另一种方法

If I specify the InstanceContextMode must be single and the the function's ReleaseInstanceMode to AfterCall this blocks any other functions from executing while the function is busy. 如果我指定InstanceContextMode必须为单个,并且函数的ReleaseInstanceMode为AfterCall,则会阻止其他任何函数在函数繁忙时执行。 It uses instance deactivation (Details found here ) 它使用实例停用(在此处找到详细信息)

<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)>
Public Class Service1

    <OperationBehavior(ReleaseInstanceMode:=ReleaseInstanceMode.AfterCall)>
    Public Function DoWork() As String
       Return WorkDone
    End Function

End Class

Will this work and is there any specific problems that I could run into? 这项工作有效吗?我有遇到任何具体问题吗?

If I was you I would prefer to make one more abstraction, as you can control restriction third party component. 如果您是我,我希望再做一个抽象,因为您可以控制限制第三方组件。

  1. You can inherit third party class (if it's a class) and organize queue inside. 您可以继承第三方类(如果是类)并在内部组织队列。 Use it as a singleton. 将其用作单例。 Singleton 独生子
  2. Using tasks and task factory with limited threads (very similar to your idea): Scheduler 在有限的线程中使用任务和任务工厂(非常类似于您的想法): 调度程序
  3. Your idea with ThreadPool. 您对ThreadPool的想法。
  4. In case it's a service, the easiest way is to create your own WCF service which will be responsible for queueing, which can be organized by WCF: Throttling 如果它是一个服务,最简单的方法是创建自己的WCF服务,将负责排队,可以通过WCF组织: 节流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM