Multi Threading

Multi Threading



Abstract:


Multi Threading Concepts in DOT Net.

Description:


To use the parent and child method for multi threading concepts.

Code:




Imports System.Threading

Module MultiThreading

Public Buffer As Integer
Public BufferEmpty As Boolean = True
Public MonitorLock As Object = New Object()

Sub Producer()
Dim Value As Integer = 0
Do
Monitor.Enter(MonitorLock)
If (BufferEmpty) Then
BufferEmpty = False
Buffer = Value

If (Value = 0) Then
Value = 1
Else
Value = 0
End If

Console.WriteLine("Parent: " & Buffer)

End If
Monitor.Exit(MonitorLock)

Loop While (True)

End Sub

Sub Consumer()

Dim Value As Integer

Do
Monitor.Enter(MonitorLock)

If (Not BufferEmpty) Then
BufferEmpty = True
Thread.CurrentThread.Sleep(1000)

Value = Buffer

Console.WriteLine("Child: " & Value)

End If

Monitor.Exit(MonitorLock)

Loop While (True)

End Sub

Sub Main()
Dim ProducerThread As Thread
Dim ConsumerThread As Thread

ProducerThread = New Thread(AddressOf Producer)
ConsumerThread = New Thread(AddressOf Consumer)

ProducerThread.Start()
ConsumerThread.Start()
End Sub

End Module


Comments

Author: Mrs. Meetu Choudhary Nanda04 Jul 2009 Member Level: Gold   Points : 1

I don't know how many times I have to ask you to format your resources. Please Post Full formatted resources.

++
Thanks and Regards
Meetu Choudhary
Site Coordinator.

Author: R.Vijayaragavan04 Jul 2009 Member Level: Gold   Points : 1

Please tell me which format code snippets posted in dotnet spider website. Please kindly send it.

Author: Manigandan04 Jul 2009 Member Level: Gold   Points : 1

Hi,


Formatted means just it should a Readable and Understandable one that's it...
Yours is just a C# Codings. There is no Special format for that.
Just post it neatly with Alignment, That what Meetu trying to say i think.





Thanks,
Mani

Author: R.Vijayaragavan04 Jul 2009 Member Level: Gold   Points : 1

Hai Mani,

Thanks for your reply. In future, am submit proper format of code snippets.

Thanks & Regards,
Vijayaragavan

Author: Mrs. Meetu Choudhary Nanda04 Jul 2009 Member Level: Gold   Points : 2

You can see this resource of yours.
I have formatted it. how it looking now and what you have posted was something a mess and unreadable.

Hope you understand now if still doubts read the forums in adout dotnet spider category or raise your question there.


++
Thanks and Regards
Miss Meetu Choudhary
Site Coordinator

Author: R.Vijayaragavan06 Jul 2009 Member Level: Gold   Points : 1

Hai Mettu,

Thanks for your reply. If any new post am align properly.

Thanks & Regards,
Vijay.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: