title: How to subscribe to events using Microsoft.Management.Infrastructure in a NetCore application?
body: <p>I'd like to know how to subscribe and receive events in a NetCore application using the library Microsoft.Management.Infrastructure.</p>
  <p>So far I'm able to query some data using something like this:</p>
  <pre class="lang-cs prettyprint-override"><code>var options = new CimSessionOptions();
  var securePassword = new SecureString();
  foreach (var c in password)
      securePassword.AppendChar(c);
  
  var credentials = new CimCredential(PasswordAuthenticationMechanism.Default, &quot;&quot;, &quot;user&quot;, securePassword);
  options.AddDestinationCredentials(GetCredentials(user, password));
  
  CimSession session = CimSession.Create(url, options);
  var queryInstance = mySession.QueryInstances(&quot;a namespace&quot;, &quot;WQL&quot;, &quot;a query&quot;);
  foreach (var instance in queryInstance)
      Console.WriteLine(instance.ToString());
  </code></pre>
  <p>Searching on Internet, I saw examples doing this using System.Management, like the following one:</p>
  <pre class="lang-cs prettyprint-override"><code>ManagementEventWatcher watcher = new ManagementEventWatcher(&quot;namespace&quot;, &quot;query&quot;);
  watcher.EventArrived += new EventArrivedEventHandler(EventArrived);
  watcher.Start();
  </code></pre>
  <p>But unfortunately I can't use this package, I just need the equivalent but using MMI.</p>
  <p>I've seen some class that maybe could help me in this task like <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.management.infrastructure.cimcmdlets.cimindicationwatcher?view=powershellsdk-1.1.0" rel="nofollow noreferrer">CimIndicationWatcher</a> which is part of the Microsoft.Management.Infrastructure.CimCmdlets package, however I imported it to my project but I can't access any of the classes in it.</p>
  <p>There's a lack of documentation/examples about the use of this class or this scenario in general.</p>