How does Process.GetCurrentProcess() work?

Merchand

Well-known member
Joined
Dec 28, 2005
Messages
73
Location
USA Eastcoast
Programming Experience
10+
How does Process.GetCurrentProcess() work?

I'm using the following code in method called GetCurrentHandle(). However, I'm expecting this to return the current handle but it is returning different handles each time. What is GetCurrentProcess really return for the Process? Just trying to learn here... :(

Dim myProcess As Process
myProcess = Process.GetCurrentProcess()
GetCurrentHandle = myProcess.Handle

Any information is greatly appreciated! :)

 
It returns a new process instance attached to the existing current process calling the method, that's why it's handle changes.
Check it's .Id, always same as long process run.
Check it's .MainWindowHandle and compare to "Me.Handle", they are always same and are also equal.
 
JohnH,

I appreciate the feedback on how this works... I checked out the online help for

VB.NET:
Process.GetCurrentProcess()

And you are correct... It just seems to me that this GetCurrentProcess is missed named and misleading.

I did get my code working! Thanks! :)
 
Back
Top