Send text output and input from 2 different forms?

  • I have 2 forms, one is the MainForm and one is RCONForm the problem I have now is that in MainForm I spawn the "RCON" process which is at the moment only a simple .bat file.

    What I am trying to do is to start the process on application start and on the second form the user can read the output and send input to the console window.


    This is my MainForm:

    https://hastebin.com/oqikepupeb.vbs


    And the RCONForm:

    https://hastebin.com/givovuyika.vbs

    (It has one output textbox and one input text box)


    The process starts just fine and keeps running in the background until the program is closed, but the problem is that I can neither see the output or send any input to the window.

    Any suggestions?


    Probably an easy thing that I can't figure out...

    If you need help with something, send me a PM!

    GitHub

    The post was edited 1 time, last by Raven ().

  • I was thinking about threads, but I find them hard to use I have not yet managed to make them properly work the way I want them to (I have not tested QuantumBug's MDL link yet).

    I want to be able to use the RCON process from any form, such as send input and read output from it.


    But I will definitely read the link thank you!

    If you need help with something, send me a PM!

    GitHub

  • Some important pointers:


    1. You have no method to update the text while your background process is running, for this you'd use

    Vbnet
    1. AddHandler, AddressOf


    which will send any changes to your sub routine at AddressOf, for example

    Vbnet
    1. AddHandler RCON.OutputDataRecieved, AddressOf NewRCONOutputData



    Now each time the console states there is a new output string, AddHandler will inform your Sub Routine "NewRCONOutputData" that an output update has been recieved. This also applies to the error handling, which would be

    Vbnet
    1. AddHandler RCON.ErrorDataReceieved, AddressOf NewRCONError



    2. Delegates for sub Routines, to keep stuff off the main thread, which will cause the UI to temporarily crash, or throw a cross-thread exception. Delegates are done as below is shown.

    Vbnet
    1. Private Delegate Sub RCONOutputDelegate(ByVal s As String)
    2. Private Sub Output(ByVal s As String)
    3. If (Me.InvokeRequired) Then
    4. Dim dDelegate As New RCONOutputDelegate(AddressOf Output)
    5. Dim obj As Object = {s}
    6. Me.Invoke(dDelegate, obj)
    7. Else
    8. RCONForm.TextBox1.AppendText(String.Concat(s, vbCrLf))
    9. End If
    10. End Sub



    I will try and write sonething up for you as an expample ASAP.


    Regards, QB.

    If debugging is the process of removing bugs, then programming must be the process of putting them in. - Edsgar Dijkstra

  • Hi dude, some source for you. Can be downloaded here.

    Source is VB.NET, CLR is .NET 4 and written in VS2013.


    Study it through and ask any questions if you have any.

    If debugging is the process of removing bugs, then programming must be the process of putting them in. - Edsgar Dijkstra