Module Module1
Sub main()
Randomize()
Dim r = New Random
Dim rLock = New Object
Dim results As New Concurrent.ConcurrentBag(Of Tuple(Of Integer, String))
Dim getRandom = New Func(Of Integer)(Function()
SyncLock rLock
Return r.Next(0, Integer.MaxValue)
End SyncLock
End Function)
' total number of loops
' v
System.Threading.Tasks.Parallel.For(0, 100, Sub(i)
Dim aRandom = getRandom()
'process the query
Dim output = "-server-response-" 'or whatever the outcome of processing
results.Add(New Tuple(Of Integer, String)(aRandom, output))
End Sub)
For Each itm In results
Console.WriteLine(itm.Item1 & vbTab & itm.Item2)
Next
End Sub
End Module
예 멀티 스레딩을 통해이 작업을 수행 할 수 있지만 쿼리의 의미는 무엇입니까? 게시 할 수 있습니까? –
기본적으로 숫자를 전송합니다 (예 : 1087673). 서버가 전체 이름을 반환합니다. – user2085339
다중 스레드를 사용하면 프로그램이 다음 요청을 시작하기 전에 각 요청이 완료 될 때까지 기다리지 않습니다. 서버가 한 번에 하나의 요청 만 처리 할 수 있기 때문에 이것이 더 빠를 지 알 수 없습니다. –