Vb Net Update Progress Bar Backgroundworker Thread Up

I have the standard progress bar and worker thread scenario with progress of the worker thread being fed back to the main UI and displayed on the progress bar. I have a delegate and am using BeginInvoke. But the progress bar is not updating. Have you come across the BackgroundWorker class yet? (new to Framework 2.0, IIRC).

Vb Net Update Progress Bar Backgroundworker Thread Up
I am new to VB.NET. I had programmed in Visual Basic 4 many many years ago. Recently I had to use Visual Studio 2010 to create a quick application for internal usage. Now there was a task which took a long time. As per good user interface design it was obvious that a progress update should be shown to keep the end user informed and updated till the task completed.
App
To cut a long story short, the requirement was to let the long running task continue while a progress bar showed the progress of the task. After searching for examples, I got a basic idea on how to use threads in VB.Net to accomplish the task I had at hand.

If a method issues an update just before it completes, the event may be raised on a thread pool thread after the task has been completed! You do need to be aware of these problems when using Progress without a UI context. We’ll cover more advanced progress composition in a later post, and consider solutions to these problems. Use BackgroundWorker Load Value to Progressbar. Use BackgroundWorker Load Value to Progressbar.

Vb Net Update Progress Bar Backgroundworker Thread Up To 10

Vb net update progress bar backgroundworker thread up to 10



Bar
I have attached the VS2010 project for you to download and see the code. The main working parts are explained here.
  • Step 1 - Create a basic Windows Form application
  • Step 2 - Create a simple Dialog and add a ProgressBar and a Label to it
  • Step 3 - Write a method which will launch a separate Thread to perform the long running task
  • Step 4 - Write Delegate methods in the Dialog
The code is self explanatory.
Code for the Main Form


Vb Net Update Progress Bar Backgroundworker Thread Upload

Download Project
UpdateI have uploaded the project as a ZIP archive on Google Drive. Click to download.

Vb Net Update Progress Bar Backgroundworker Thread Up Free

Hello all
Yes I know its been done before, but something silly is killing me on
this.
I have the standard progress bar and worker thread scenario with
progress of the worker thread being fed back to the main UI and
displayed on the progress bar. I have a delegate and am using
BeginInvoke. But the progress bar is not updating.
I have simplified my code below(and also built and tested this code).
Basic form1 with progress bar and button nothing else.
--------------------------------------------------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Threading
Imports System.IO
Public Class Form1
Dim worker As System.Threading.Thread ' Thread
Dim worker_obj As New worker_class ' Object from
worker class
Public Sub New()
Me.InitializeComponent()
'ProgressBar1
ProgressBar1.Name = 'ProgressBar1'
ProgressBar1.Maximum = 100
ProgressBar1.Value = 10
End Sub
Sub UpdateProgressDisplay(ByVal Value_for_progress_bar As Integer)
ProgressBar1.Value = Value_for_progress_bar
Application.DoEvents()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
worker = New Thread(AddressOf
worker_obj.DoRemoteCommunications)
' Now actually start the comms thread.
worker.Start()
End Sub
End Class
Public Class worker_class
' Set up delegate for assync function call.
--------------------------------
Public Delegate Sub Async_Update_Progress_caller(ByVal
Value_for_progress_bar As Integer)
Public Sub DoRemoteCommunications()
Console.WriteLine('Comms worker thread started.....')
' Set up delegate to allow asynchronous calls between threads.
Dim caller As New Async_Update_Progress_caller(AddressOf
Form1.UpdateProgressDisplay)
' Initiate the asynchronous call.
Dim result As IAsyncResult
result = caller.BeginInvoke(100, Nothing, Nothing)
Console.WriteLine('Progress value 25 passed ')
Thread.Sleep(3000)
Console.WriteLine('Comms worker thread Finished.')
End Sub
End Class
--------------------------------------------------------------------------------------------
Many thanks for any help.
Denis
_______________________
http://www.CentronSolutions.com