What is FreeThreading ?

A thread is an independent flow of control that operates with in the same address space as other independent flow of control that operates with in the process. As everyone is aware that windows is a pre-emptive multi-tasking system.

 

Free threading allows the application to perform tasks independently.  Moreover debugging a free- threaded application can be a nightmare. When more than one process is running and process are sharing a common memory there is a high possibility of complicated bugs.

 

Some of the applications will be beneficiary using the free- threading concepts as mentioned below

 

  • Applications that perform process control

  • Applications that perform High data access

 

  • Applications that are communication over the internet

 

  • Applications that implements Queuing (MSMQ).

 

In order to use free threading in VB.NET we need implement the System.Threading namespace. 

 

 Dim othread  as new System.Threading.thread ( Addressof    someSub)

     othread. Start ()  - This statement Kicks off the thread

 

SyncLock

 

We can use the SyncLock command to help prevent the problems when working with objects in multithreaded environment. The SyncLock command accepts an object as the key and locks the object from being accessed by the other threads.

 

 Private Shared Sub Add(x As Object)

      SyncLock GetType(Cache)

      End SyncLock

 End Sub

 

 By key, we mean a unique identifier that identifies an object. The importance of SyncLock in multithreaded environment is different threads tries to access an object which will cause system instability or crash.

 

Check out the code sample which demonstrated the SyncLock…

 

Private Sub SyncLockExample()

       syncLock (button1)

            button1.Text = “ Do this Processing ”

       End SyncLock

End sub

 

In the above code “button1” object is locked to prevent other threads to access this object. A good threadsafe code is written by properly using multithreading and paying attention to the application design properly. Threadsafe code operates properly when more than one thread executes it.

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish