Jump to content
alogrep

WMI (winspool) and critical section

Recommended Posts

HI.

Is accessing  WMI thread safe?
I mean this:
I my Thread repeatedly list the print jobs in the sn spool with  this code
 
 FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
    FWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', WbemUser, WbemPassword);
    FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PrintJob','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
    etc. ......

Do I need to protect that with a criticalsection Acquire/Release?

Thank you

Share this post


Link to post

I have used WMI in multiple simultaneous threads before but always created and kept the WMI Objects local to each thread.

 

Are you sure there is no other API/way to do what you want? WMI generally is slow.

Edited by PeaShooter_OMO

Share this post


Link to post

Yes, there other ways, but they do not work

Anyway, in EACH thread I have a funtcion that  does this

FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
    FWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', WbemUser, WbemPassword);
    FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PrintJob','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
    etc. ......

My question is: do i need to encapsulatwe it in a critical section Acquire/Release?. ( I am rather new to threads, but I would think it is not necessary)

Share this post


Link to post

Thanks.

It seems then I do not need to use a critical section because each thread instantiate the object and use the service. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×