diff options
author | sr55 <[email protected]> | 2007-06-13 17:48:48 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2007-06-13 17:48:48 +0000 |
commit | babd31063ad5762ecf9d0b42f2dd1a2093ab3ecb (patch) | |
tree | ef2b1c5614933d717c3b01364708046411b26218 /win/Handbrake/frmQueue.vb | |
parent | a69ea7b548f56de0b074d4e125361bd89ab2f584 (diff) |
Windows Source Code
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@614 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/Handbrake/frmQueue.vb')
-rw-r--r-- | win/Handbrake/frmQueue.vb | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/win/Handbrake/frmQueue.vb b/win/Handbrake/frmQueue.vb new file mode 100644 index 000000000..bc1090343 --- /dev/null +++ b/win/Handbrake/frmQueue.vb @@ -0,0 +1,136 @@ +Imports System.IO
+Imports System
+Imports System.Diagnostics
+Imports System.Threading
+Imports System.ComponentModel
+Imports System.Windows.Forms
+
+Public Class frmQueue
+
+
+ Delegate Sub SetTextCallback(ByVal [text] As Integer)
+
+ '#
+ '# Buttons
+ '#
+ Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
+ list_queue.Items.Remove(list_queue.SelectedItem)
+ End Sub
+
+ Private Sub btn_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Close.Click
+ Me.Hide()
+ End Sub
+
+ '# STAGE 1
+ Private Sub btn_q_encoder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_q_encoder.Click
+
+ Dim ApplicationPath As String = Application.StartupPath ' The applications start parth
+ Dim encodeItems As Integer = list_queue.Items.Count ' Amount of items to encode
+
+ encodeItems = encodeItems - 1
+
+ 'Start the encode process
+ Try
+ Shell("""" + ApplicationPath + "\hbcli.exe""" + list_queue.Items.Item(encodeItems))
+ Catch ex As Exception
+ MessageBox.Show("ERROR: No items left on the queue. Code: 01")
+ End Try
+
+ ' Lets start the process monitor
+ hbcliMonitor = New ProcessMonitor()
+ Dim t = New Thread(AddressOf hbcliMonitor.tmrProcCheck)
+ t.Start()
+
+ Try
+ ' When this task is finished, remove it from the queue
+ list_queue.Items.RemoveAt(encodeItems)
+ Catch ex As Exception
+ ' quietly ignore the error should the user try to encode with nothing on the queue by mistake.
+ End Try
+
+ End Sub
+
+
+
+ '# STAGE 2
+ Sub TheadCompletedMonitor(ByVal isRunning As Integer) Handles hbcliMonitor.ThreadComplete
+
+ Dim ApplicationPath As String = Application.StartupPath ' The applications start parth
+ Dim encodeItems As Integer = list_queue.Items.Count ' Amount of items to encode
+
+ encodeItems = encodeItems - 1
+
+
+ If encodeItems = -1 Then
+ MessageBox.Show("Status: Queue completed!")
+ Else
+ 'Start the encode process
+ Try
+ Shell("""" + ApplicationPath + "\hbcli.exe""" + list_queue.Items.Item(encodeItems))
+ Catch ex As Exception
+ MessageBox.Show("Error Code: q1, Please report this error.")
+ End Try
+
+ ' Lets start the process monitor
+ hbcliMonitor = New ProcessMonitor()
+ Dim t = New Thread(AddressOf hbcliMonitor.tmrProcCheck)
+ t.Start()
+
+ ' When this task is finished, remove it from the queue
+ Me.SetText(encodeItems)
+ 'MsgBox("1 Enocde Process Finished: ", isRunning)
+ End If
+
+ End Sub
+
+
+ '#
+ '# Trying to safely alter stuff on the worker thread here.
+ '#
+ Private Sub SetText(ByVal [text] As Integer)
+ If Me.list_queue.InvokeRequired Then
+ Dim d As New SetTextCallback(AddressOf SetText)
+ Me.Invoke(d, New Object() {[text]})
+ Else
+ Me.list_queue.Items.RemoveAt([text])
+ End If
+ End Sub
+
+ '#
+ '# Process Monitoring Stuff Here
+ '#
+
+ Dim WithEvents hbcliMonitor As ProcessMonitor
+
+ Public Class ProcessMonitor
+ Public isRunning As Integer = 1
+
+ Public Event ThreadComplete(ByVal isRunning As Integer)
+
+ Public Sub tmrProcCheck()
+ Dim isRunning As Integer
+ Dim process2 As Process = New Process
+ Dim running As Boolean = True
+ Dim hbProcess As Process() = Process.GetProcesses()
+
+ While running
+ Thread.Sleep(1000)
+ hbProcess = Process.GetProcesses()
+ running = False
+ Dim processArr2 As Process() = hbProcess
+ Dim i As Integer = 0
+ While i < CInt(processArr2.Length)
+ Dim process1 As Process = processArr2(i)
+ If process1.ProcessName.Equals("hbcli") Then
+ running = True
+ End If
+ i = i + 1
+ End While
+ End While
+ isRunning = 0
+ RaiseEvent ThreadComplete(isRunning)
+ End Sub
+ End Class
+
+
+End Class
\ No newline at end of file |