我有以下问题,希望有人能帮助我。取消后台工作人员
我有一个工作在运行shell程序的VB.net(2010)。
shell程序是服务输出的东西,如:
Server initializing...
Server opening port...
more info...
我能“抓”外壳的输出,并把它添加到一个文本框(使用设置文本功能)。
,我能够通过点击STOPBUTTON取消了工人,然而,当有由外壳输出没有更多的,我不能停止的工人了。
至少我怀疑是这样。
我试过检查endofstream(注释部分),但不工作。
我也试过同样的代码在“clsProcess.StandardOutput.ReadLine”代替一些测试文本,并且也有效。
所以,我得出的结论,必须有一些做与clsProcess.StandardOutput.ReadLine是在最后???
Try
clsProcess.StartInfo.UseShellExecute = False
clsProcess.StartInfo.RedirectStandardOutput = True
clsProcess.StartInfo.RedirectStandardError = True
clsProcess.StartInfo.FileName = serverpath + config_executable
clsProcess.StartInfo.CreateNoWindow = True
clsProcess.Start()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error starting server")
Debug.Print(ex.Message)
End Try
Do While Not workerServer.CancellationPending
Try
'If Not clsProcess.StandardOutput.EndOfStream Then
SetText(clsProcess.StandardOutput.ReadLine + vbNewLine)
'End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error adding line to log")
End Try
Threading.Thread.Sleep(100)
Loop
clsProcess.Kill()
任何想法?
在此先感谢!
问候,
PH
你能后的代码在你停止按钮的点击事件?和代码可能调用的任何相关函数? – overslacked 2010-11-15 19:57:01