You can think of ref as creating an alias for a variable. This does not mean that the variable that you pass is "passed by reference", it is that the parameter and the argument are the same variable, just two names. Therefore, the update immediately updates the other, because there really aren't two things.
As Slacks notes, there are situations in VB that use copy-in-copy-out semantics. There are also, if I remember correctly, rare and obscure situations in which expression trees can be compiled into copy-in-copy code, but I donβt remember the details.
If this code is designed to update a variable for reading in another thread, then the fact that the variable is updated immediately is misleading. Remember that on multiple threads, you can observe that reading and writing move forward and backward in time with respect to each other if reads and writes are unstable. If the goal is to use this variable as a mechanism for exchanging across multiple threads, then they use an object specifically designed for this purpose, which is safe for this purpose. Use some kind of wait descriptor or mutex or something else.
source share