0

In Mac OS X I can take advantage of more than 1 core using GCD (Grand Central Dispatch). What is the equivalent for a Visual Basic program?

Sachin Chavan
  • 5,578
  • 5
  • 49
  • 75
foobar5512
  • 2,470
  • 5
  • 36
  • 52

2 Answers2

1

Threading in VB.NET can be very simple.

Shared Sub New()
    Dim t As New System.Threading.Thread(AddressOf GetWebpage)
    t.Start()
End Sub

All the above is doing is causing a function to be executed in its own thread.

Here's the function being called:

Private Shared Sub GetWebpage()
        Dim URL As String = ConfigurationManager.AppSettings("AppCacheURL")
        Dim REQ As System.Net.HttpWebRequest = System.Net.WebRequest.Create(URL & "?Task=PopulateURLCache&Payload=App_Start")
        REQ.GetResponse()
End Sub

This is a simplified example of an asyncronous call to a function that fires an HTTP Request to a webpage. The original code is a little more complex with error handling and logging, but it basically causes a "keep alive" style aspx page to be accessed without slowing down the calling application. (Fire and forget)

If you need a framework or library to accomplish your goals, have a look at:

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
0

You should look at PLINQ and the Task Parallel Library, both of which can be used to utilise the number of cores available in a host computer for performing CPU bound operations.

Joseph Albahari has a great tutorial on using Parallel Programming techniques (in C#), but the exact same concepts apply to VB.NET.

RichardOD
  • 28,883
  • 9
  • 61
  • 81