Page 1 of 1

Backgroundwork + progressbar

Posted: Thu Mar 18, 2010 1:03 am
by MiztaInsane
So I have this code in backgroundwork2.dowork how can i show the progress of this in progressbar2
Code: Select all
Dim myJob As New Job2Convert()
        Dim ms As New MediaServer()
        myJob.pszSrcFile = "C:\Users\Devin\Desktop\Release\test.wmv" 'THE FILE TO CONVERT
        myJob.pszDstFile = "C:\Users\Devin\Desktop\Release\test.avi" 'THE FILENAME TO SAVE IT AS
        myJob.pszDstFormat = "avi" 'FORMAT TO CONVERT TOO
        myJob.pszAudioCodec = "aac" 'AUDIO CODEC TO USE
        myJob.nAudioChannels = 2
        myJob.nAudioBitrate = -1
        myJob.nAudioRate = -1
        myJob.pszVideoCodec = "h264" 'VIDEO CODEC TO USE
        myJob.nVideoBitrate = -1
        myJob.nVideoFrameRate = -1
        myJob.nVideoFrameWidth = -1
        myJob.nVideoFrameHeight = -1
        Dim ret As Boolean = ms.ConvertFile(myJob)
thanks

Re: Backgroundwork + progressbar

Posted: Mon Mar 22, 2010 2:43 pm
by Harlem9191
Insert the following code into the subroutine you want to start the process. I'm guessing it is a button so put it in the click event.
Code: Select all
Dim Strt As System.Threading.Thread
Strt = New System.Threading.Thread(AddressOf MyThread1)
Strt.Start()
Just copy and paste this and delete your old code:
Code: Select all
Sub MyThread1()
        Dim myJob As New Job2Convert()
        Dim ms As New MediaServer()
        myJob.pszSrcFile = "C:\Users\Devin\Desktop\Release\test.wmv" 'THE FILE TO CONVERT
        myJob.pszDstFile = "C:\Users\Devin\Desktop\Release\test.avi" 'THE FILENAME TO SAVE IT AS
        myJob.pszDstFormat = "avi" 'FORMAT TO CONVERT TOO
        myJob.pszAudioCodec = "aac" 'AUDIO CODEC TO USE
        myJob.nAudioChannels = 2
        myJob.nAudioBitrate = -1
        myJob.nAudioRate = -1
        myJob.pszVideoCodec = "h264" 'VIDEO CODEC TO USE
        myJob.nVideoBitrate = -1
        myJob.nVideoFrameRate = -1
        myJob.nVideoFrameWidth = -1
        myJob.nVideoFrameHeight = -1
        Dim ret As Boolean = ms.ConvertFile(myJob)
End Sub

Should work like a charm. But remember, don't try to update controls when using this code. For example, don't try adding something to a listbox or update a progress bar. If you're trying to do that it gets a little more complicated.

Re: Backgroundwork + progressbar

Posted: Tue Mar 23, 2010 12:40 pm
by MiztaInsane
Thank you for your help. how can i show the progress of this in the progressbar?

thanks you again

Re: Backgroundwork + progressbar

Posted: Wed Mar 24, 2010 12:39 am
by Harlem9191
You would most likely have to use a background worker instead. Check out this: http://www.java2s.com/Code/VB/GUI/Backg ... erDemo.htm

You would have to do a little rewrite of the code I gave you if you want to use this method. Try to avoid cross-thread errors. They can be a pain..

Re: Backgroundwork + progressbar

Posted: Wed Mar 24, 2010 12:01 pm
by MiztaInsane
thanks yeh they can be a pain lol

thanks for your help again hope to return the help someday

Re: Backgroundwork + progressbar

Posted: Thu Mar 25, 2010 9:14 pm
by Harlem9191
If you have any problems then just post back on here and I will have a look at the code you've got.