Imports System.IO Imports System.Threading Public Class Form1 Public tInterval As Integer Public Writer As Thread Public func As Thread = New Thread(AddressOf processStarter) Public read As Thread = New Thread(AddressOf fileReader) Public a As Integer Public p As Process = New Process Public reader As String Public Function fileWriter() Dim wri As StreamWriter wri = File.CreateText(Application.StartupPath + "\fix.bat") wri.WriteLine("@echo off") wri.WriteLine("cls") wri.WriteLine("echo HELLO WORLD") wri.WriteLine("echo pause") wri.WriteLine("pause") wri.Close() a = 1 Return a End Function Public Function processStarter() p.StartInfo.FileName = Application.StartupPath + "\fix.bat" p.StartInfo.Arguments = "" p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.StartInfo.Verb = "runas" p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized p.Start() read.Start() Return 0 End Function Public Function fileReader() Try MsgBox("I HAVE OPENED") reader = p.StandardOutput.ReadToEnd RichTextBox1.Text = reader Catch ex As Exception MsgBox(ex.Message) End Try Return 0 End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True Timer1.Start() Button1.Text = "Please Wait.." Button1.Enabled = False End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load tInterval = 0 a = 0 End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick tInterval = tInterval + 1 Label1.Text = Str(tInterval) End Sub Private Sub Label1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.TextChanged If tInterval = 1 Then Writer = New Thread(AddressOf fileWriter) Writer.Start() End If If tInterval = 2 Then Timer1.Stop() Writer.Abort() func.Start() End If End Sub End Class
tInterval
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)