Variables and Their Scope

The last topic that we will tackle with regards to threads is that of variable access and scope. What happens when more than one thread is executing a body of code where a variable is defined? Is that variable's value unique across the instances of the thread, or is it shared? In this section, we will look at how variables interoperate between threads. We will then look at ways that we can explicitly tell VB .NET to create variables that are private to a specific thread.

General Scope Rules

Consider if we had a class that defined the following variables:

Class ourClass
    Private a As Integer
    Private Shared b As Integer
    Shared c As Integer

    Sub ourMethod()
              Dim d As Integer
    End Sub
End Class

How would you expect these different ...

Get Visual Basic® Programmer's Guide to the .NET Framework Class Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.