@@ -33,6 +33,7 @@ Public Class Form1
3333 OutputBrowseBtn.Enabled = False
3434 BitrateNumberBox.Enabled = False
3535 enableMultithreading.Enabled = False
36+ CPUThreads.Enabled = False
3637 Running = True
3738 End Sub
3839 Private Sub StartBtn_Click(sender As Object , e As EventArgs) Handles StartBtn.Click
@@ -120,7 +121,7 @@ Public Class Form1
120121 FileAlreadyExist.Add(args( 1 ))
121122 End If
122123 Next
123- Parallel.Invoke( New ParallelOptions With {.MaxDegreeOfParallelism = Environment.ProcessorCount }, tasks.ToArray())
124+ Parallel.Invoke( New ParallelOptions With {.MaxDegreeOfParallelism = CPUThreads.Value }, tasks.ToArray())
124125 Else
125126 For Counter As Integer = 0 To ItemsToProcess.Count - 1
126127 Dim args As Array = {ItemsToProcess(Counter), GetOutputPath(OutputTxt.Text, ItemsToProcess(Counter)), My.Settings.Bitrate}
@@ -147,6 +148,7 @@ Public Class Form1
147148 StartBtn.Enabled = True
148149 BitrateNumberBox.Enabled = True
149150 enableMultithreading.Enabled = True
151+ CPUThreads.Enabled = True
150152 InputTxt.Enabled = True
151153 OutputTxt.Enabled = True
152154 InputBrowseBtn.Enabled = True
@@ -252,16 +254,21 @@ Public Class Form1
252254 InputPipe.WaitForConnection()
253255 Dim ChunkSize As Integer = 16384
254256 For Bytes As Long = 0 To Input.Length Step 16384
255- If Input.Length - Bytes < ChunkSize Then
256- ChunkSize = Input.Length - Bytes
257- End If
258- Await InputPipe.WriteAsync(Input, Bytes, ChunkSize)
257+ Try
258+ If Input.Length - Bytes < ChunkSize Then
259+ ChunkSize = Input.Length - Bytes
260+ End If
261+ Await InputPipe.WriteAsync(Input, Bytes, ChunkSize)
262+ Catch
263+ End Try
259264 Next
260265
261266 InputPipe.Flush()
262267 InputPipe.Dispose()
263268 End Sub
264269 Private Sub Form1_Load(sender As Object , e As EventArgs) Handles MyBase .Load
270+ CPUThreads.Maximum = Environment.ProcessorCount
271+ If My.Settings.CPUThreads = 0 Then CPUThreads.Value = CPUThreads.Maximum Else CPUThreads.Value = My.Settings.CPUThreads
265272 BitrateNumberBox.Value = My.Settings.Bitrate
266273 enableMultithreading.Checked = My.Settings.Multithreading
267274 EncFfmpeg1.Checked = My.Settings.EncFfmpeg
@@ -394,4 +401,8 @@ Public Class Form1
394401 End If
395402 End Sub
396403
404+ Private Sub CPUThreads_ValueChanged(sender As Object , e As EventArgs) Handles CPUThreads.ValueChanged
405+ My.Settings.CPUThreads = CPUThreads.Value
406+ My.Settings.Save()
407+ End Sub
397408End Class
0 commit comments