1

我有一个来自外部网络服务的搜索功能。搜索一天的数据返回记录数大约需要 3 秒。要求连续搜索一个月的数据。

所以进行普通搜索是不明智的(大约需要 90 秒)。

我想使用开始和结束日期作为参数进行搜索功能并返回记录数。并在 for 循环中调用此函数(更改日期范围)并在完成后汇总记录。

我认为最好的方法是执行任务或线程。但我无法成功地做到这一点。

所以它将需要 3 秒而不是 90 秒。

在这方面的任何帮助都将得到很大的利用。

4

1 回答 1

0

如果我正确地阅读了你的问题,这应该让你开始:

Module modSum

Private mSum As Integer
Public Property Sum() As Integer
    Get
        Return mSum
    End Get
    Set(ByVal value As Integer)
        mSum = value
    End Set
End Property

Public Sub DoSum()

    For i = 1 To 30

        Dim dateToQuery As Date
        dateToQuery = Date.Parse("2013-02-" & i.ToString)


        Dim sc As New WebserviceCall
        sc.startdate = "2013-01-01"
        sc.enddate = "2013-01-31"

        Dim th As New Threading.Thread(AddressOf sc.DoServiceCall)
        th.Start()

    Next

End Sub

Public Class WebserviceCall

    Public startdate As Date
    Public enddate As Date

    Public Sub DoServiceCall()

        Dim ws As New YourService.Service
        Dim result As Integer = ws.GetSum(startdate, enddate)

        mSum += result

    End Sub

End Class

End Module
于 2013-02-03T22:20:45.630 回答