Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How we can implement Parallel Processes in VB.Net

Author: DevASP
Download Source Code : 572_Parallel Process.zip

This Article helps you to understand the use Parallel Processes to achieve concurrency in tasks. This Article does not include synchronization, because no data is being accessed by multiple threads.

This Article does not include synchronization, as it is not needed for this code. However, when using multiple threads and sharing data, synchronization is critical.

Because Parallel Processes code presents complexities when stepping through it, the Debugger Step Through attribute is applied at the multithreaded points. Attempting to step through the Parallel Processes sections may yield inconsistent results. This example only writes to each window from the thread that is managing it. When writing to a window from threads other than the Parallel Processes managing that window, additional attention is required. An asynchronous delegate is an easy way to run a task on a worker thread, but is not the only way to do so.

Source Code is Given For Your Bettter Understanding.

Display the main thread for the application.

Write this code in the Load event. Then make this event function.and write the code. 'Run the task on the same thread that is managing the frmMain window. To run the task on a worker pool thread, you can use an asynchronous invocation on a delegate. For this example, we'll declare a delegate named TaskDelegate, and call it asynchronously. The signature of the delegate declaration must match the method (TheLongRunningTask)exactly.

To run the task an a thread from the worker pool, create an instance

 of a delegate whose signature matches the method that will be called,

then call BeginInvoke on that delegate. For this example, the arguments

and return value of BeginInvoke are unneeded. This technique is sometimes referred to as "Fire and Forget". To run the task on a newly created OS thread (rather than a tread from the thread pool), create a new instance of a managed thread. The constructor takes the address of a subroutine with no arguments. Runs on a worker thread from the pool.

 

Private Sub cmdSameThread_Click(ByVal sender As System.Object, _

                                 ByVal e As System.EventArgs) _

                                 Handles cmdSameThread.Click

 

            TheLongRunningTask()

 

End Sub

 

Private Sub cmdWorkerPoolThread_Click( _

ByVal sender As System.Object, _ByVal e As System.EventArgs) _

   Handles cmdWorkerPoolThread.Click

Dim td As New TaskDelegate(AddressOf TheLongRunningTask) td.BeginInvoke(Nothing, Nothing)

End Sub

 

This function Actually Creates the new thread'Begins the execution of the new thread. This method simulates some long-running task. To represent the work in progress, a form with a progress bar will display during its execution.

The method displays the form, then updates the progress bar every half second for 5 seconds. After simulating the task, the form is taken down.

Refresh causes an instant (non-posted) display of the label.

Slowly increment the progress bar. Remove the form after the "task" finishes.

 

Private Sub cmdRunOnNewWin32Thread_Click( _

ByVal sender As System.Object, _ByVal e As System.EventArgs) _

                                         Handles cmdRunOnNewWin32Thread.Click

 

Dim t As New Thread(AddressOf TheLongRunningTask)

t.Start()

End Sub

 

Private Sub TheLongRunningTask()

Dim f As New frmTaskProgress()

f.Show()

f.Refresh()

 

        Dim i As Integer

        For i = 1 To 10

            f.prgTaskProgress.Value += 10

            Thread.CurrentThread.Sleep(500) 'half-second delay

        Next

            f.Hide()

            f.Dispose()

      End Sub

Source Code is Given with that Article. Please Run it Will helps u allot.

Article Comments
How we can implement Parallel Processes in VB.Net

Posted on 4/6/2007 2:42:22 AM by Senthil Kumar

Actually, I am working as a Team Manager-Production in Data Conversion industry where i am working for new processes.
1. What kind of things keeping in mind while working for any existing work.
2. For tracking of jobs through online system
3. Automatically mails to be send after feeding entry into the online system.

Posted on 12/20/2007 6:24:49 AM by Prem Prakash Satyawali

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How we can Use the XMLDocument Class in VB.Net

Disclaimer - Privacy
© 2002-2017 DevASP.net