vb.Net控制台应用程序在会话后运行异步

时间:2016-03-19 14:18:52

标签: php vb.net

我正在尝试创建一个程序来设置telnet连接以将数据发送到我托管的服务器。带有参数的命令行。这个应用程序将通过PHP启动,但PHP将保持页面加载,直到procces完成。这可能需要一段时间。所以我正在寻找如何在控制台应用程序关闭后执行procces。不要让PHP等到任务完全完成。
我试图使应用程序成为可编程的' cmd的telnet连接器
这是我目前的代码:

Dim output As String = ""
    Dim telnet As TcpClient
    Dim Send As String
    Sub Main()
        Dim args As New List(Of String)
        Dim script As String = ""
        For Each arg As String In Environment.GetCommandLineArgs()
            If (arg.Equals(Assembly.GetExecutingAssembly().Location)) Then
                Continue For
            Else
                args.Add(arg)
            End If
        Next
        script = My.Computer.FileSystem.ReadAllText(args(0))
        script = script.Replace("\;", "#comm_sla#")
        Dim script_in_part As List(Of String) = script.Split(";").ToList()
        Write("Found " + script_in_part.Count.ToString() + " lines")
        For Each scriptpart As String In script_in_part
            scriptpart = scriptpart.Replace("#comm_sla#", ";")
            scriptpart = scriptpart.Replace(";", "")
            scriptpart = scriptpart.Replace(vbNewLine, "")
            Write("Executing: " + scriptpart)
            Dim scr() As String = scriptpart.Split(" ")
            If scr(0).Equals("connect") Then
                Try
                    telnet = New TcpClient(scr(1), Integer.Parse(scr(2)))
                    Write("Connected")
                Catch ex As Exception
                    Write("Error=Cant connect, host or port meight be invalid")
                End Try
            End If
            If scr(0).Equals("disconnect") Then
                telnet.Client.Disconnect(False)
            End If
            If scr(0).Equals("start") Then
                If scr(1).Equals("session") Then
                    Write("Async session started")
                    Dim trh As Threading.Thread = New Threading.Thread(AddressOf start_session)
                    trh.Start()
                End If
            End If
        Next
        Console.WriteLine(output)
    End Sub
    Private Sub start_session(state As Object)
        While True

connection meganism will come here

        MsgBox("test")
        Threading.Thread.Sleep(1000)
    End While
End Sub
Private Sub Write(ByVal str As String)
    output = output + str + ";"
End Sub

感谢您的帮助!

0 个答案:

没有答案