Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '/---------------------- Form designer ---------------------/'
- '/------------------- Visual Studio 15.7.4 ----------------/'
- <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
- Partial Class Form1
- Inherits System.Windows.Forms.Form
- 'Form overrides dispose to clean up the component list.
- <System.Diagnostics.DebuggerNonUserCode()> _
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- Try
- If disposing AndAlso components IsNot Nothing Then
- components.Dispose()
- End If
- Finally
- MyBase.Dispose(disposing)
- End Try
- End Sub
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.IContainer
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> _
- Private Sub InitializeComponent()
- Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
- Me.Button1 = New System.Windows.Forms.Button()
- Me.lbl_status = New System.Windows.Forms.Label()
- Me.SuspendLayout()
- '
- 'RichTextBox1
- '
- Me.RichTextBox1.BackColor = System.Drawing.Color.FromArgb(CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer))
- Me.RichTextBox1.ForeColor = System.Drawing.Color.White
- Me.RichTextBox1.Location = New System.Drawing.Point(12, 76)
- Me.RichTextBox1.Name = "RichTextBox1"
- Me.RichTextBox1.Size = New System.Drawing.Size(457, 153)
- Me.RichTextBox1.TabIndex = 0
- Me.RichTextBox1.Text = ""
- '
- 'Button1
- '
- Me.Button1.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(CType(CType(128, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
- Me.Button1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
- Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
- Me.Button1.Font = New System.Drawing.Font("Segoe UI", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Button1.ForeColor = System.Drawing.Color.White
- Me.Button1.Location = New System.Drawing.Point(12, 24)
- Me.Button1.Name = "Button1"
- Me.Button1.Size = New System.Drawing.Size(88, 35)
- Me.Button1.TabIndex = 1
- Me.Button1.Text = "Start"
- Me.Button1.UseVisualStyleBackColor = True
- '
- 'lbl_status
- '
- Me.lbl_status.Font = New System.Drawing.Font("Segoe UI", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.lbl_status.ForeColor = System.Drawing.Color.White
- Me.lbl_status.Location = New System.Drawing.Point(244, 25)
- Me.lbl_status.Name = "lbl_status"
- Me.lbl_status.Size = New System.Drawing.Size(225, 32)
- Me.lbl_status.TabIndex = 2
- Me.lbl_status.TextAlign = System.Drawing.ContentAlignment.MiddleRight
- '
- 'Form1
- '
- Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
- Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
- Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer))
- Me.ClientSize = New System.Drawing.Size(481, 244)
- Me.Controls.Add(Me.lbl_status)
- Me.Controls.Add(Me.Button1)
- Me.Controls.Add(Me.RichTextBox1)
- Me.ForeColor = System.Drawing.Color.Black
- Me.Name = "Form1"
- Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
- Me.Text = "Form1"
- Me.ResumeLayout(False)
- End Sub
- Friend WithEvents RichTextBox1 As RichTextBox
- Friend WithEvents Button1 As Button
- Friend WithEvents lbl_status As Label
- End Class
- '/----------------------------- Code ----------------------------------/'
- Imports System.Diagnostics
- Imports System.IO
- 'This code uses the Process.SynchronizingObject property, thus the it doesn't really need
- 'MethodInvoker. It's added anyway (in the Event Handler) to see how it could work.
- 'It doesn't modify the Process.OutputDataReceived results in any way.
- 'Delete .SynchronizingObject = Me from the Process contructor to activate it
- Public Class Form1
- Private myappthing_proc As Process
- Private myappthing_proc_state As Boolean
- Private ProcessExitCode As Integer = -1
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- StartProcess()
- End Sub
- Private Sub StartProcess()
- lbl_status.Text = "Status: Running"
- Dim MyStartInfo As New ProcessStartInfo()
- MyStartInfo.FileName = "tracert.exe"
- MyStartInfo.Arguments = "www.microsoft.com"
- MyStartInfo.WorkingDirectory = Path.Combine(Application.StartupPath, "backend")
- MyStartInfo.RedirectStandardError = True
- MyStartInfo.RedirectStandardOutput = True
- MyStartInfo.UseShellExecute = False
- MyStartInfo.CreateNoWindow = True
- MyStartInfo.WindowStyle = ProcessWindowStyle.Hidden
- myappthing_proc = New Process() With {
- .EnableRaisingEvents = True,
- .StartInfo = MyStartInfo,
- .SynchronizingObject = Me
- }
- myappthing_proc_state = True
- myappthing_proc.Start()
- myappthing_proc.BeginErrorReadLine()
- myappthing_proc.BeginOutputReadLine()
- AddHandler myappthing_proc.OutputDataReceived,
- Sub(sender As Object, e As DataReceivedEventArgs)
- If e.Data IsNot Nothing Then
- Dim output As String = e.Data.Replace("[0m", "")
- If InvokeRequired Then
- Dim mi As MethodInvoker =
- Sub()
- RichTextBox1.AppendText(output + Environment.NewLine)
- RichTextBox1.ScrollToCaret()
- End Sub
- Invoke(mi)
- Else
- RichTextBox1.AppendText(output + Environment.NewLine)
- RichTextBox1.ScrollToCaret()
- End If
- End If
- End Sub
- AddHandler myappthing_proc.ErrorDataReceived,
- Sub(sender As Object, e As DataReceivedEventArgs)
- If e.Data IsNot Nothing Then
- Dim output As String = e.Data.Replace("[0m", "")
- If InvokeRequired Then
- Dim mi As MethodInvoker =
- Sub()
- RichTextBox1.AppendText(output + Environment.NewLine)
- RichTextBox1.ScrollToCaret()
- End Sub
- Invoke(mi)
- Else
- RichTextBox1.AppendText(output + Environment.NewLine)
- RichTextBox1.ScrollToCaret()
- End If
- End If
- End Sub
- AddHandler myappthing_proc.Exited,
- Sub(source As Object, ev As EventArgs)
- ProcessExitCode = myappthing_proc.ExitCode
- myappthing_proc.Close()
- If Not (IsNothing(myappthing_proc)) Then
- myappthing_proc.Dispose()
- End If
- lbl_status.Text = "Status: Exited"
- myappthing_proc_state = False
- End Sub
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment