public static void SubscribeSync(CimSession cimSession, string cimNamespace) { try { string query = QueryInstanceCore(); //Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Press <Enter> to abort the subscription"); //Console.ResetColor(); CancellationTokenSource cts = new CancellationTokenSource(); CimOperationOptions cimOperationOptions = new CimOperationOptions { CancellationToken = cts.Token }; IEnumerable <CimSubscriptionResult> queryInstances = cimSession.Subscribe(cimNamespace, "WQL", query, cimOperationOptions); IEnumerator <CimSubscriptionResult> queryEnumerator = queryInstances.GetEnumerator(); Thread waitUserInputThread = new Thread(SubscribeSyncReal); waitUserInputThread.Start(queryEnumerator); Console.ReadLine(); cts.Cancel(); queryEnumerator.Dispose(); } catch (CimException ex) { PrintCimException(ex); } catch (Exception ex) { Console.WriteLine(ex.Message); } }