我有一个应用程序,它具有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