views:

35

answers:

1

Hi,

Can any one please advise me how I can get the current count of "USER Object"s (as shown in task manager) for the current process.

I see how to get the handle count using:

Process.GetCurrentProcess.HandleCount

But our application can reach a USER Object count of 10,000 just by opening 17 instances of a particular form so we would like to try and warn a user that resources are getting low before they reach teh limit and the application bombs.

Thanks in advance.

Best regards, Duane.

+1  A: 

If I'm thinking of the right kinds of user objects you can do it with the GetGuiResources API function. See the pinvoke page for it here for a C# sample (the second one that sends in 1 as the flag).

Here's a VB translation of the code:

Imports System.Runtime.InteropServices

<DllImport("User32")> _
Public Shared Function GetGuiResources(ByVal hProcess As IntPtr, ByVal uiFlags As Integer) As Integer
End Function

Public Shared Function GetGuiResourcesUserCount() As Integer
    Return GetGuiResources(Process.GetCurrentProcess().Handle, 1)
End Function
ho1
That is perfect. Thank you.
Dib