vb.net - 如何返回所有线程都在函数中完成?
问题描述
我有这段代码,它通过遍历字符串列表来启动一些线程,并将每个线程发送到Sub
连接到 web 服务并等待结果的 a:
Public Shared Function StartThreading(names As String())
Dim threads As List(Of Thread) = New List(Of Thread)()
For Each name In names
Dim t As Thread = New Thread(New ParameterizedThreadStart(Sub() CallWebService(name)))
threads.Add(t)
Next
For i As Integer = 0 To threads.Count - 1
Dim t = threads(i)
Dim name = names(i)
t.Start(name)
Next
For Each t As Thread In threads
t.Join()
Next
End Function
Web 服务调用者的 Sub 是:
Public Shared Sub CallWebService(inputxml As String)
Dim _url = "http://10.231.58.173:8080/ps/services/ProcessServer?WSDL"
Dim _action = "http://10.231.58.173:8080/ps/services/ProcessServer"
Dim soapEnvelopeXml As XmlDocument = CreateSoapEnvelope(inputxml)
Dim webRequest As HttpWebRequest = CreateWebRequest(_url, _action)
Dim appPath As String = System.AppDomain.CurrentDomain.BaseDirectory
Dim configpath As String = appPath + "\Config.ini"
Dim configdata As IniData = Functii.ReadIniFile(configpath)
Dim outputxmlsave = configdata("PATHS")("OUTPUTXML")
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest)
Dim asyncResult As IAsyncResult = webRequest.BeginGetResponse(Nothing, Nothing)
asyncResult.AsyncWaitHandle.WaitOne()
Dim soapResult As String
Using webResponse As WebResponse = webRequest.EndGetResponse(asyncResult)
Using rd As StreamReader = New StreamReader(webResponse.GetResponseStream())
soapResult = rd.ReadToEnd()
End Using
File.WriteAllText(outputxmlsave & "\" & "test.xml", soapResult.ToString)
Console.Write(soapResult)
End Using
End Sub
我怎么知道所有线程是否成功完成?True
如果它们都完成了,我可以用什么来返回一个值吗?
解决方案
推荐阅读
- json - 服务人员我想将 fetch 响应传递给另一个 fetch
- ruby - 使用 .include 忽略字符串中的大小写?
- amazon-web-services - 使用带有 boto python API 的 lambda 读取 AWS ec2 实例的详细信息导致“EC2”对象没有属性“Instance”
- reactjs - 尝试从符号链接导入时 React 崩溃
- html - 在移动设备上垂直居中元素
- python - 语法错误,我不知道为什么 Python
- java - @Value 在单元测试中返回 null
- sharepoint - 如何为并发项目创建图表
- typescript - 如何在 WebStorm 中抑制 TS2322 警告?
- java - 在 Linux VM 机器上运行 FREngine