0

Hello! Does anyone know how to set a progress bar? I am developing an audio and video converter manager. I wanted the progress bar to run 'til the process of the converting of file is finished. The converting time depends on the file size so I can't just set the maximum and minimum counter. Can anyone give me an idea or teach me how to do it? It would be a lot of help on my thesis project. Thanks a lot in advance! ^_^ By the way I am using Visual Studio 2008. :D

chellemits

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by sgt_toasty
0

try using Threading:

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Threading

Namespace WFInvoke
	Public Partial Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		<STAThread> _
		Private Shared Sub Main()
			Application.Run(New Form1())
		End Sub

		Private Sub IncrementMe()
			'Instead of this loop use your code for converting
			For i As Integer = 0 To 99
				UpdateProgress()
				Thread.Sleep(100)
			Next
			If InvokeRequired Then
				Invoke(New MethodInvoker(AddressOf Close))
			Else
				Close()
			End If
		End Sub

		Private Sub UpdateProgress()
			If Me.progressBar1.InvokeRequired Then
				Dim updateProgress__1 As MethodInvoker = AddressOf UpdateProgress
				progressBar1.Invoke(updateProgress__1)
			Else
				progressBar1.Increment(1)
			End If
		End Sub

		Private Sub button1_Click(sender As Object, e As EventArgs)
			Dim threadStart As ThreadStart = AddressOf IncrementMe
			threadStart.BeginInvoke(Nothing, Nothing)
		End Sub
	End Class
End Namespace
0

Thank you Mitja! I'll try to study this one and apply it to my codes. I'll get back to you if this works for my project. God bless! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.