क्योंकि मुझे यकीन नहीं है कि यह क्या कारण है, मेरे पास हैसभी कोड को कॉपी और पेस्ट करना, अगर नियम के विरुद्ध क्षमा करें। यह कार्यक्रम विज़ुअल बेसिक 2010 में लिखा गया है और रोबोकॉपी को संचालित करने के लिए इसे cmd का उपयोग करना चाहिए और फिर वास्तविक समय में परिणाम प्रदर्शित करें। यह ऐसा करता है, लेकिन कुछ उपयोगों के बाद लटक जाता है, मैं इस कोडिंग में नया हूं और यह भी सुनिश्चित नहीं हूं कि थ्रेड को कैसे संभालना है, इसलिए यह हो सकता है लेकिन मुझे नहीं पता कि इसे कैसे ठीक किया जाए।
अगर कोई मेरी मदद कर सकता है तो मैं बहुत आभारी रहूंगा :)
Public Class Form1
Private Results As String
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Dim button_click As Integer = 0
Dim myProcess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Dim Folder_TBC As String
Dim Folder_DES As String
Dim RoboCommand As String
Private Sub UpdateText()
" TextBox_CMDout.Text = Results
TextBox_CMDout.AppendText(System.Environment.NewLine() & Results)
TextBox_CMDout.ScrollToCaret()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If button_click = 0 Then
RoboCommand = Chr(34) + TextBox_FolderTBC.Text + Chr(34) + " " + Chr(34) + TextBox_FolderDes.Text + Chr(34) + " "
If CheckBox_ISF.Checked = True Then RoboCommand = RoboCommand + "/S "
If CheckBox_MUT.Checked = True Then RoboCommand = RoboCommand + "/MT "
If CheckBox_MOV.Checked = True Then RoboCommand = RoboCommand + "/Move "
opencmd()
button_click += 1
End If
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub opencmd()
StartInfo.FileName = "cmd" "starts cmd window
StartInfo.UseShellExecute = False "required to redirect
StartInfo.CreateNoWindow = True "creates no cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.RedirectStandardError = True
myProcess.StartInfo = StartInfo
myProcess.Start()
End Sub
Private Sub CMDAutomate()
"Dim SR As System.IO.StreamReader = myprocess.StandardOutput
"Dim SW As System.IO.StreamWriter = myprocess.StandardInput
myProcess.StandardInput.WriteLine("robocopy " & Folder_TBC & Folder_DES)
myProcess.StandardInput.WriteLine(System.Environment.NewLine())
" SW.WriteLine("exit") "exits command prompt window
While myProcess.StandardOutput.EndOfStream = False
Results = myProcess.StandardOutput.ReadLine()
Invoke(Finished)
End While
"Results = SR.ReadToEnd "returns results of the command window
"SW.Close()
"SR.Close()
"invokes Finished delegate, which updates textbox with the results text
Application.ExitThread()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FolderBrowserDialog1.ShowDialog()
TextBox_FolderTBC.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
FolderBrowserDialog1.ShowDialog()
TextBox_FolderDes.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Application.ExitThread()
Application.Exit()
End
End Sub
अंत कक्षा
उत्तर:
जवाब के लिए 0 № 1जब अगला क्लिक संसाधित होता है, तो TextBox_CMDout पाठ को साफ़ करें, आप बार-बार सभी आउटपुट को समेट रहे हैं
आगे मुझे लगता है कि आपका समाधान एफएआर बहुत जटिल है जो आप करना चाहते हैं।
इसे आज़माएं (और अपने टेक्स्टबॉक्स से सही मापदंडों को भरें), अधिक आवश्यक नहीं है और "जब आप सीएमडी कमांड से बाहर निकलते हैं तो विषयों से बचते हैं?" और इसी तरह।
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "Robocopy"
myProcess.StartInfo.Arguments = "/?"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
TextBox_CMDout.Text = myProcess.StandardOutput.ReadToEnd()
myProcess.WaitForExit()
myProcess.Close()