How to Cancel a WMI Query

156 views
Skip to first unread message

Dennis Macdonald

unread,
Apr 19, 2012, 8:53:24 PM4/19/12
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

I have initiated a WMI query, see below;

Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT *
FROM Win32_Product")
For Each queryObj As ManagementObject In searcher.Get()
..... DO WORK HERE
Next

How to I abort this Get call because it takes approx 60 seconds on my
comuter (I know the time will differ between computers) but I need to
be able to cancel it.

Note, putting a exit look does not help because it does not enter the
loop until after the query has executed.


Any ideas?

Thanks,
Dennis.

Stephen Russell

unread,
Apr 20, 2012, 7:58:56 AM4/20/12
to dotnetde...@googlegroups.com
-----------------------

Is this run in command line? If so try a Ctrl + C to send a cancel
message. Untested advise here. :)

--
Stephen Russell

901.246-0159 cell

Reuben Bartolo

unread,
Apr 20, 2012, 3:31:08 AM4/20/12
to dotnetde...@googlegroups.com
Why not put it in its own thread, and then you will not care about how long it takes, since your program will still be responsive?

Reuben

--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetde...@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Dennis Macdonald

unread,
Apr 24, 2012, 7:33:20 PM4/24/12
to dotnetde...@googlegroups.com
It is already in its own thread (a BackgroundWorker) but when I issue a CancelAsync it hanges waiting on the WMI query to finish.
 
So, I need to be acle to abort the actual WMI query?
 
Thanks,
Dennis.

On Friday, April 20, 2012 5:31:08 PM UTC+10, Reuben Bartolo wrote:
Why not put it in its own thread, and then you will not care about how long it takes, since your program will still be responsive?

Reuben
On 20 April 2012 02:53, Dennis Macdonald <band...@gmail.com> wrote:
Hi,

I have initiated a WMI query, see below;

Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT *
FROM Win32_Product")
For Each queryObj As ManagementObject In searcher.Get()
      ..... DO WORK HERE
Next

How to I abort this Get call because it takes approx 60 seconds on my
comuter (I know the time will differ between computers) but I need to
be able to cancel it.

Note, putting a exit look does not help because it does not enter the
loop until after the query has executed.


Any ideas?

Thanks,
Dennis.

--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetdevelopment@googlegroups.com

To unsubscribe from this group, send email to

Dennis Macdonald

unread,
Apr 24, 2012, 7:33:42 PM4/24/12
to dotnetde...@googlegroups.com
No, its part of a much larger program.

Reuben Bartolo

unread,
Apr 25, 2012, 5:01:27 AM4/25/12
to dotnetde...@googlegroups.com
Once the thread runs, and is doing its work, you will not have full control over it, and that is a GOOD thing.
Let me explain why.

Imagine you are making use of resources. Once you cancel the work being done, your smart code will have to clean up after you, by releasing resources, and doing other such things. You do NOT want to simply stop immediately, with all locks and handles still in place.

For this reason, once you cancel a task, it might still stay running for a while. But if it is already in a thread, simply kill the thread, and ignore how long it takes to actually die. Just remember to ignore any results it might return.



To post to this group, send email to dotnetde...@googlegroups.com

To unsubscribe from this group, send email to
Reply all
Reply to author
Forward
0 new messages