What does address of operator do in background?

Q

What does address of operator do in background?

✍: Guest

A

The AddressOf operator creates a delegate object to the BackgroundProcess method. A delegate within VB.NET is a type-safe, object-oriented function pointer. After the thread has been instantiated, you begin the execution of the code by calling the Start() method of the thread



When we instantiate a new Thread class we pass it a reference to the code block we want to execute in the constructor of the Thread class. The following code creates a new Thread object and passes it a reference to BackgroundProcess:

Dim t As Thread
t = New Thread(AddressOf Me.BackgroundProcess)
t.Start()

The AddressOf operator here creates a delegate object to the BackgroundProcess method. And the execution is resume after the Start method is called.

2009-03-06, 8050👍, 0💬