我有一個應用程序,它具有2/3選擇的控制檯菜單。一個過程涉及上傳文件並對其內容執行冗長的搜索過程,而另一個過程涉及SQL查詢並且是與用戶的交互過程。我希望使用線程來允許一個進程運行,而菜單提供第二個進程運行的選項。但是,您不能運行第一個過程兩次。 我創建了線程並更正了一些編譯錯誤,但線程選項無法正常工作。任何幫助讚賞。使用菜單選項中的線程
main...
Dim tm As Thread = New Thread(AddressOf loadFile)
Dim ts As Thread = New Thread(AddressOf reports)
....
While Not response.Equals("3")
Try
Console.Write("Enter choice: ")
response = Console.ReadLine()
Console.WriteLine()
If response.Equals("1") Then
Console.WriteLine("Thread 1 doing work")
tm.SetApartmentState(ApartmentState.STA)
tm.IsBackground = True
tm.Start()
response = String.Empty
ElseIf response.Equals("2") Then
Console.WriteLine("Starting a second Thread")
ts.Start()
response = String.Empty
End If
ts.Join()
tm.Join()
Catch ex As Exception
errormessage = ex.Message
End Try
End While
我意識到,基於將是更容易的形式與也許只是調用不同的形式來處理processes.But我真的沒有這個選項,因爲現在的控制檯應用程序稍後將加入到API的實現。但是這裏是我的兩個菜單功能的過程。也不知道如何處理布爾型變量,如下所示。
Private Sub LoadFile()
Dim dialog As New OpenFileDialog
Dim response1 As String = Nothing
Dim filepath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
dialog.InitialDirectory = filepath
If dialog.ShowDialog() = DialogResult.OK Then
fileName = dialog.FileName
ElseIf DialogResult.Cancel Then
Exit Sub
End If
Console.ResetColor()
Console.Write("Begin Search -- Discovery Search, y or n? ")
response1 = Console.ReadLine()
If response1 = "y" Then
Search()
ElseIf response1 = "n" Then
Console.Clear()
main()
End If
isRunning = False
End Sub
,第二個
Private Shared Sub report()
Dim rptGen As New SearchBlogDiscovery.rptGeneration
Console.WriteLine("Tread Process started")
rptGen.main()
Console.WriteLine("Thread Process ended")
isRunning = False
End Sub
請描述什麼是「工作不正常」,其實就是 – 2010-03-29 14:52:21