そのため、ファイル名のリストに基づいて、サードパーティのexeを起動してファイル操作を実行するアプリケーションを作成しようとしています。したがって、リストに 13 個の項目がある場合、外部プロセスを開始するたびにループを 13 回実行し、現在処理されているファイルをユーザーに通知し、プロセスを開始して終了するのを待ちます。ユーザーに通知するために、別のリストボックスがシャウトボックスとして使用されます。問題は、 .waitforexit() が何らかの形でスレッド全体を奇妙な方法でフリーズさせるため、外部プログラムが正常に呼び出され、ファイルは正常に処理されますが、すべての項目が完了するまでメイン ウィンドウがフリーズすることです。したがって、基本的に、Shoutbox はフリーズし、ループ全体が終了した後でのみ、すべての情報でスパムされます。これを実装するために、新しいスレッドの開始、スレッドプール、タイマーなどの使用など、さまざまな方法を試しました。どんな助けでも大歓迎です。コード:
Imports System.Windows.Threading
Imports System.Windows.Forms
Imports System.IO
Imports System.Threading
If Listbox2.Items.Count > 0 Then
tabctrl.SelectedIndex = 2
Listbox3.Items.Add(DateTime.Now.ToString & ": Process initiated.")
For i = 0 To Listbox2.Items.Count - 1
Listbox3.Items.Add(DateTime.Now.ToString & ": Processing :" & Listbox1.Items.Item(i))
If System.IO.File.Exists(Listbox2.Items.Item(i)) = False Then
Dim pInfo As New ProcessStartInfo()
With pInfo
.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
.FileName = System.IO.Directory.GetCurrentDirectory & "\" & "myapp.exe"
.argouments = "w/e"
End With
Dim p As Process = Process.Start(pInfo)
p.WaitForExit()
p.Dispose()
Else
Listbox3.Items.Add(DateTime.Now.ToString & ":! " & Listbox2.Items.Item(i) & " already exists. Moving to next file..")
End If
Next
Listbox3.Items.Add("*-*")
Listbox3.Items.Add(DateTime.Now.ToString & ": Done.")
End If