{"id":2781,"date":"2012-05-24T15:39:18","date_gmt":"2012-05-24T06:39:18","guid":{"rendered":"http:\/\/nanoappli.com\/blog\/?p=2781"},"modified":"2012-05-24T15:39:18","modified_gmt":"2012-05-24T06:39:18","slug":"cwmi%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e3%82%92managementeventwatcher%e3%82%af%e3%83%a9%e3%82%b9%e3%81%a7%e5%87%a6%e7%90%86%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/nanoappli.com\/blog\/archives\/2781","title":{"rendered":"[C#]WMI\u30a4\u30d9\u30f3\u30c8\u3092ManagementEventWatcher\u30af\u30e9\u30b9\u3067\u51e6\u7406\u3059\u308b"},"content":{"rendered":"<p>\nWindows\u3067\u306f\u3001WMI(Windows Management Instrumentation)\u306eAPI\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001OS\u3092\u69cb\u6210\u3057\u3066\u3044\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u64cd\u4f5c\u51fa\u6765\u307e\u3059\u3002<br \/>\n<br \/>\nWMI\u3067\u306f\u901a\u5e38\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u3084\u30bb\u30c3\u30c8\u3092\u884c\u3046\u4e8b\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\u3057\u3066\u304a\u304f\u4e8b\u3067\u3001\u6307\u5b9a\u3057\u305f\u72b6\u6cc1\u304c\u767a\u751f\u3057\u305f\u304b\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u691c\u51fa\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n\u4eca\u56de\u306f\u3001C#\u3088\u308a.Net Framework\u306eManagementEventWatcher\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u53d6\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u3001PC\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306e\u8f1d\u5ea6\u304c\u5909\u66f4\u3055\u308c\u305f\u4e8b\u3092\u30a4\u30d9\u30f3\u30c8\u3068\u3057\u3066\u691c\u51fa\u3057\u3001\u30a4\u30d9\u30f3\u30c8\u60c5\u5831\u3092\u753b\u9762\u306b\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n<h2>\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u306e\u767b\u9332<\/h2>\n<br \/>\nWMI\u30a4\u30d9\u30f3\u30c8\u3092\u53d7\u4fe1\u3059\u308b\u4e0a\u3067\u3001\u6700\u521d\u306b\u884c\u3046\u4e8b\u306f\u30a4\u30d9\u30f3\u30c8\u306e\u76e3\u8996\u51e6\u7406\u3067\u3059\u3002<br \/>\n\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u306f\u3001\u76e3\u8996\u306e\u958b\u59cb\u51e6\u7406\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<br \/>\n<pre lang=\"csharp\">\nManagementEventWatcher watcher;\n\npublic Form1() {\n    InitializeComponent();\n    SetEventHandler();\n}\n\n\/\/*********************************************************************\n\/\/\/ <summary>\u3000\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306e\u8f1d\u5ea6\u304c\u5909\u308f\u3063\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\u3059\u308b\n\/\/\/ <\/summary>\n\/\/*********************************************************************\nvoid SetEventHandler() {\n    \/\/-------------------------------------------------------------------\n    \/\/ \u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306e\u8f1d\u5ea6\u304c\u5909\u308f\u3063\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\n    \/\/-------------------------------------------------------------------\n    string              scope    = @\"root\\wmi\";\n    string              queryStr = \"SELECT * FROM WmiMonitorBrightnessEvent\";\n    EventWatcherOptions option   = new EventWatcherOptions( null, new TimeSpan( 0, 0, 1 ), 1 );\n    watcher = new ManagementEventWatcher( scope, queryStr, option );\n\n    \/\/--------------------------------\n    \/\/ \u30a4\u30d9\u30f3\u30c8\u53d7\u4fe1\u6642\u306e\u30cf\u30f3\u30c9\u30e9\u3092\u5b9a\u7fa9\n    \/\/--------------------------------\n    watcher.EventArrived += new EventArrivedEventHandler( BrightnessEventArrived );\n\n    \/\/--------------------------------\n    \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u76e3\u8996\u3092\u958b\u59cb\u3059\u308b\n    \/\/--------------------------------\n    watcher.Start();\n}\n<\/pre>\n<br \/>\n\u307e\u305a\u3001SetEventHandler()\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u3001ManagementEventWatcher\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<pre lang=\"csharp\">\nstring              scope    = @\"root\\wmi\";\nstring              queryStr = \"SELECT * FROM WmiMonitorBrightnessEvent\";\nEventWatcherOptions option   = new EventWatcherOptions( null, new TimeSpan( 0, 0, 1 ), 1 );\nwatcher = new ManagementEventWatcher( scope, queryStr, option );\n<\/pre>\n<br \/>\n\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u7b2c\u4e00\u5f15\u6570\u3067\u306fWMI\u306e\u30b9\u30b3\u30fc\u30d7\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4f8b\u3067\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u8d77\u52d5\u3057\u3066\u3044\u308bPC\u306b\u5bfe\u3057\u3066WMI API\u3092\u30b3\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4ed6\u306ePC\u3092\u5bfe\u8c61\u3068\u3057\u305f\u3044\u5834\u5408\u306f\u3001@&#8221;\\\\hostname\\root\\wmi&#8221; \u306e\u5f62\u5f0f\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u7b2c\u4e8c\u5f15\u6570\u306b\u3066\u3001\u4f55\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u53d6\u308a\u305f\u3044\u304b\u3092WQL\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u7b2c\u4e09\u5f15\u6570\u3067\u306f\u30a4\u30d9\u30f3\u30c8\u76e3\u8996\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u307e\u3059(\u7701\u7565\u53ef)\u3002<br \/>\n<br \/>\n<br \/><br \/>\n<pre lang=\"csharp\">\nwatcher.EventArrived += new EventArrivedEventHandler( BrightnessEventArrived );\n<\/pre>\n\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u305f\u3089\u3001\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306e\u30cf\u30f3\u30c9\u30e9\u30e1\u30bd\u30c3\u30c9\u3092\u767b\u9332\u3057\u307e\u3059\u3002<br \/>\nBrightnessEventArrived()\u306e\u4e2d\u8eab\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/><br \/>\n<pre lang=\"csharp\">\nwatcher.Start();\n<\/pre>\n\u305d\u306e\u5f8c\u3001Start()\u30e1\u30bd\u30c3\u30c9\u3092\u30b3\u30fc\u30eb\u3059\u308b\u4e8b\u3067\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u76e3\u8996\u304c\u884c\u308f\u308c\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n<h2>\u30a4\u30d9\u30f3\u30c8\u767a\u751f\u6642\u306e\u51e6\u7406<\/h2>\n<br \/>\n\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\u3057\u305f\u3089\u3001\u6b21\u306f\u5b9f\u969b\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u306f\u3001EventArrived\u3067\u6307\u5b9a\u3057\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n<pre lang=\"csharp\">\n\/\/*********************************************************************\n\/\/\/ <summary>   \u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306e\u8f1d\u5ea6\u304c\u5909\u308f\u3063\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"sender\"><\/param>\n\/\/\/ <param name=\"e\"><\/param>\n\/\/*********************************************************************\npublic void BrightnessEventArrived( object sender, EventArrivedEventArgs e ) {\n    ManagementNamedValueCollection ctx      = e.Context  as ManagementNamedValueCollection;\n    ManagementBaseObject           newEvent = e.NewEvent;\n\n    StringBuilder tmpBuff = new StringBuilder();\n\n\n    \/\/----------------------------\n    \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u60c5\u5831\u3092\u53d6\u5f97\n    \/\/----------------------------\n\n    \/\/ \u30a4\u30d9\u30f3\u30c8\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u60c5\u5831\u3092\u30c0\u30f3\u30d7\n    tmpBuff.AppendLine( \"[Properties]\" );\n    foreach ( PropertyData prop in newEvent.Properties ) {\n        tmpBuff.Append( prop.Name + \"=\" );\n        tmpBuff.AppendLine( prop.Value == null ? \"null\" : prop.Value.ToString() );\n    }\n\n    \/\/ WMI\u30b7\u30b9\u30c6\u30e0\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u60c5\u5831\u3092\u30c0\u30f3\u30d7\n    tmpBuff.AppendLine( \"[SystemProperties]\" );\n    foreach( PropertyData sysProp in newEvent.SystemProperties ) {\n        tmpBuff.Append( sysProp.Name + \"=\" );\n        tmpBuff.AppendLine( sysProp.Value == null ? \"null\" : sysProp.Value.ToString() );\n    }\n\n    \/\/ WMI\u4fee\u98fe\u5b50\u306e\u60c5\u5831\u3092\u30c0\u30f3\u30d7\n    tmpBuff.AppendLine( \"[Qualifier]\" );\n    foreach( QualifierData qualifier in newEvent.Qualifiers ) {\n        tmpBuff.Append( qualifier.Name + \"=\" );\n        tmpBuff.AppendLine( qualifier.Value == null ? \"null\" : qualifier.Value.ToString() );\n    }\n\n    \/\/--------------------------------------------\n    \/\/ \u30a4\u30d9\u30f3\u30c8\u60c5\u5831\u3092\u753b\u9762\u306b\u8868\u793a\n    \/\/ (UI\u30b9\u30ec\u30c3\u30c9\u5074\u3067\u3001UpdateText()\u3092\u30b3\u30fc\u30eb\u3059\u308b)\n    \/\/--------------------------------------------\n    UpdateTextDelegate updateTextDelegate = new UpdateTextDelegate( UpdateText );\n    this.Invoke( updateTextDelegate, new object[] { tmpBuff.ToString() });\n    \n    \/\/\u3000\u3053\u308c\u306fNG\n    textBox1.Text = tmpBuff.ToString();\n}\n<\/pre>\n<br \/>\n\u6307\u5b9a\u3057\u305f\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3059\u308b\u3068\u3001\u672c\u30e1\u30bd\u30c3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<br \/>\n\u30a4\u30d9\u30f3\u30c8\u306e\u5185\u5bb9\u306f\u3001\u7b2c\u4e8c\u5f15\u6570\u306eEventArrivedEventArgs\u3067\u6e21\u3055\u308c\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306e\u4f8b\u3067\u306f\u3001\u3053\u306e\u5185\u5bb9\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u30c0\u30f3\u30d7\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n\u624b\u5143\u306e\u74b0\u5883\u3067\u672c\u51e6\u7406\u3092\u5b9f\u884c\u3057\u305f\u7d50\u679c\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_03.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_03.jpg\" alt=\"\" title=\"20120524_03\" width=\"491\" height=\"260\" class=\"alignnone size-full wp-image-2796\" \/><\/a><br \/>\n<pre lang=\"x\">\n[Properties]\nActive=True\nBrightness=63\nInstanceName=DISPLAY\\LEN4014\\4&33df4d60&0&UID67568640_0\nSECURITY_DESCRIPTOR=null\nTIME_CREATED=129823120747750013\n\n[SystemProperties]\n__GENUS=2\n__CLASS=WmiMonitorBrightnessEvent\n__SUPERCLASS=WMIEvent\n__DYNASTY=__SystemClass\n__RELPATH=WmiMonitorBrightnessEvent.InstanceName=\"DISPLAY\\\\LEN4014\\\\4&33df4d60&0&UID67568640_0\"\n__PROPERTY_COUNT=5\n__DERIVATION=System.String[]\n__SERVER=null\n__NAMESPACE=null\n__PATH=null\n\n[Qualifier]\nabstract=True\ndynamic=True\n<\/pre>\n<br \/>\n\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bUI\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u6b8b\u5ff5\u306a\u304c\u3089\u3053\u308c\u306f\u51fa\u6765\u307e\u305b\u3093.<br \/>\n<pre lang=\"csharp\">\ntextBox1.Text = tmpBuff.ToString();\n<\/pre>\n<br \/>\n\u8a66\u3057\u306b\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bInvalidOperationException\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_04.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_04-500x284.jpg\" alt=\"\" title=\"20120524_04\" width=\"500\" height=\"284\" class=\"alignnone size-large wp-image-2797\" srcset=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_04-500x284.jpg 500w, http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_04.jpg 593w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\n<br \/>\n<br \/>\n\u3053\u308c\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u306e\u51e6\u7406\u304c\u3001UI\u30b9\u30ec\u30c3\u30c9\u3068\u306f\u5225\u306e\u30b9\u30ec\u30c3\u30c9\u3067\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002\u30b9\u30ec\u30c3\u30c9\u4e00\u89a7\u306e\u30a6\u30a3\u30f3\u30c9\u30a6\u3067\u78ba\u8a8d\u3059\u308b\u3068\u3001\u78ba\u304b\u306b\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u7528\u306e\u30ef\u30fc\u30ab\u30fc\u30b9\u30ec\u30c3\u30c9\u304c\u8d70\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_05.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_05-500x162.jpg\" alt=\"\" title=\"20120524_05\" width=\"500\" height=\"162\" class=\"alignnone size-large wp-image-2798\" srcset=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_05-500x162.jpg 500w, http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_05.jpg 823w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\n<br \/>\n\u3053\u306e\u3088\u3046\u306a\u72b6\u6cc1\u3067\u3001GUI\u4e0a\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u64cd\u4f5c\u3057\u305f\u3044\u5834\u5408\u306f\u3001Form.Invoke()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u89e3\u6c7a\u65b9\u6cd5\u304c\u4e00\u822c\u7684\u3067\u3059\u3002\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001Invoke()\u3092\u30b3\u30fc\u30eb\u3059\u308b\u4e8b\u3067\u3001\u6307\u5b9a\u3057\u305f\u30e1\u30bd\u30c3\u30c9(\u306edelegate)\u3092\u3001UI\u30b9\u30ec\u30c3\u30c9\u5074\u3067\u5b9f\u884c\u3059\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n<pre lang=\"csharp\">\n\/\/--------------------------------------------\n\/\/ \u30a4\u30d9\u30f3\u30c8\u60c5\u5831\u3092\u753b\u9762\u306b\u8868\u793a\n\/\/ (UI\u30b9\u30ec\u30c3\u30c9\u5074\u3067\u3001UpdateText()\u3092\u30b3\u30fc\u30eb\u3059\u308b)\n\/\/--------------------------------------------\nUpdateTextDelegate updateTextDelegate = new UpdateTextDelegate( UpdateText );\nthis.Invoke( updateTextDelegate, new object[] { tmpBuff.ToString() });\n<\/pre>\n<br \/>\n<br \/>\n\u5b9f\u969b\u306b\u30b3\u30fc\u30eb\u3055\u308c\u308bUpdateText()\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<br \/>\n<pre lang=\"csharp\">\n\/\/*********************************************************************\n\/\/\/ <summary>   textBox\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3055\u305b\u308b\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"text\"><\/param>\n\/\/*********************************************************************\nprivate void UpdateText( string text ) {\n    textBox1.Text = text;\n}\n\ndelegate void UpdateTextDelegate( string text );\n<\/pre>\n<br \/>\n<br \/>\n<br \/>\n<h2>WMI\u30a4\u30d9\u30f3\u30c8\u76e3\u8996\u306e\u7d42\u4e86\u51e6\u7406<\/h2>\n<br \/>\nManagementEventWatcher\u3092\u4f7f\u7528\u3057\u3066\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u76e3\u8996\u3092\u884c\u3063\u305f\u5834\u5408\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u7d42\u4e86\u524d(\u4e00\u822c\u7684\u306b\u306fForm_Closed\u30a4\u30d9\u30f3\u30c8\u7b49)\u3067\u3001Stop()\u30e1\u30bd\u30c3\u30c9\u3092\u30b3\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<pre lang=\"csharp\">\n\/\/*********************************************************************\n\/\/\/ <summary>   \u30d5\u30a9\u30fc\u30e0\u304c\u9589\u3058\u305f\u3068\u304d\u306e\u30cf\u30f3\u30c9\u30e9\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"sender\"><\/param>\n\/\/\/ <param name=\"e\"><\/param>\n\/\/*********************************************************************\nprivate void Form1_FormClosed( object sender, FormClosedEventArgs e ) {\n    \/\/----------------------\n    \/\/ WMI\u306e\u76e3\u8996\u3092\u505c\u6b62\u3059\u308b\n    \/\/----------------------\n    if ( watcher != null ) {\n        watcher.Stop();\n        watcher = null;\n    }\n}\n<\/pre>\n<br \/>\n\u3082\u3057Stop()\u3092\u547c\u3073\u5fd8\u308c\u308b\u3068\u3001\u7d42\u4e86\u6642\u306b\u4ee5\u4e0b\u306e\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u4f8b\u5916\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u975e\u5e38\u306b\u5206\u304b\u308a\u8f9b\u304f\u539f\u56e0\u306e\u7279\u5b9a\u304c\u96e3\u3057\u3044\u306e\u3067\u3001\u5fd8\u308c\u305a\u306b\u7d42\u4e86\u51e6\u7406\u3092\u884c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_06.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_06.jpg\" alt=\"\" title=\"20120524_06\" width=\"482\" height=\"313\" class=\"alignnone size-full wp-image-2799\" srcset=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_06.jpg 482w, http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120524_06-461x300.jpg 461w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/a><br \/>\n<pre lang=\"x\">\nSystem.Runtime.InteropServices.InvalidComObjectException \u306f\u30cf\u30f3\u30c9\u30eb\u3055\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002\n  Message=\u57fa\u306b\u306a\u308b RCW \u304b\u3089\u5206\u5272\u3055\u308c\u305f COM \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3046\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\n  Source=mscorlib\n  StackTrace:\n       \u5834\u6240 System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis, IntPtr pThread)\n       \u5834\u6240 System.Management.IWbemServices.CancelAsyncCall_(IWbemObjectSink pSink)\n       \u5834\u6240 System.Management.SinkForEventQuery.Cancel()\n       \u5834\u6240 System.Management.ManagementEventWatcher.Stop()\n       \u5834\u6240 System.Management.ManagementEventWatcher.Finalize()\n  InnerException: \n<\/pre>\n<br \/>\n<br \/>\n<a href=\"http:\/\/www.amazon.co.jp\/exec\/obidos\/ASIN\/4789818454\/amaxi-22\/\" target=\"_blank\"><img src=\"http:\/\/ec2.images-amazon.com\/images\/I\/51FBWNZA6EL._SL160_.jpg\" alt=\"4789818454\" border=\"0\" \/><\/a><br \/>\n<a href=\"http:\/\/www.amazon.co.jp\/exec\/obidos\/ASIN\/4789818454\/amaxi-22\/\" target=\"_blank\">WMI\u30b7\u30b9\u30c6\u30e0\u7ba1\u7406\u958b\u767a\u30c6\u30af\u30cb\u30c3\u30af<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u3067\u306f\u3001WMI(Windows Management Instrumentation)\u306eAPI\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001OS\u3092\u69cb\u6210\u3057\u3066\u3044\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u64cd\u4f5c\u51fa\u6765\u307e\u3059\u3002 WMI\u3067\u306f\u901a\u5e38\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u3084\u30bb\u30c3\u30c8\u3092\u884c\u3046\u4e8b\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\u3057\u3066\u304a\u304f\u4e8b\u3067\u3001\u6307\u5b9a\u3057\u305f\u72b6\u6cc1\u304c\u767a\u751f\u3057\u305f\u304b\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u691c\u51fa\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002 \u4eca\u56de\u306f\u3001C#\u3088\u308a.Net Framework\u306eManagementEventWatcher\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u53d6\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u3001PC\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306e\u8f1d\u5ea6\u304c\u5909\u66f4\u3055\u308c\u305f\u4e8b\u3092\u30a4\u30d9\u30f3\u30c8\u3068\u3057\u3066\u691c\u51fa\u3057\u3001\u30a4\u30d9\u30f3\u30c8\u60c5\u5831\u3092\u753b\u9762\u306b\u51fa\u529b\u3059\u308b\u30d7\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[95],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":23,"url":"http:\/\/nanoappli.com\/blog\/archives\/23","url_meta":{"origin":2781,"position":0},"title":"[C#]PC\u306e\u30b5\u30b9\u30da\u30f3\u30c9\u3001\u30ec\u30b8\u30e5\u30fc\u30e0\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u691c\u51fa\u3059\u308b","date":"2011\u5e7412\u670823\u65e5","format":false,"excerpt":"\u6982\u8981 \u30ce\u30fc\u30c8PC\u3067\u306f\u3001\u30d0\u30c3\u30c6\u30ea\u30fc\u6d88\u8cbb\u3092\u6291\u3048\u308b\u70ba\u306b\u3001\u3088\u304fPC\u306e\u30b5\u30b9\u30da\u30f3\u30c9\uff65\u30ec\u30b8\u30e5\u30fc\u30e0\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002 \u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/1223_2.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6885,"url":"http:\/\/nanoappli.com\/blog\/archives\/6885","url_meta":{"origin":2781,"position":1},"title":"C#\u3067Reactive Extensions(Rx)\u305d\u306e1:\u307e\u305a\u306fIObserver, IObservable\u3092\u7406\u89e3\u3059\u308b","date":"2016\u5e742\u67088\u65e5","format":false,"excerpt":"\u4eca\u56de\u3088\u308a\u3001C#\u3067Rx\u306e\u4f7f\u3044\u65b9\u3092\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002 Rx\u306f\u30c7\u30b6\u30a4\u30f3\u30d1\u30bf\u30fc\u30f3\u306e\uff11\u3064\u3067\u3042\u308b\u306eObserve\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6552,"url":"http:\/\/nanoappli.com\/blog\/archives\/6552","url_meta":{"origin":2781,"position":2},"title":"[Unity]uGUI\u3067\u3001\u30dc\u30bf\u30f3\u306e\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3092\u81ea\u52d5\u3067\u30bb\u30c3\u30c8\u3059\u308b\u3002","date":"2015\u5e744\u670812\u65e5","format":false,"excerpt":"Unity\u306euGUI\u3092\u4f7f\u7528\u3057\u3066\u30dc\u30bf\u30f3\u3092\u4f5c\u308b\u5834\u5408\u3001Unity\u306e\u30a4\u30f3\u30b9\u30da\u30af\u30bf\u3067\u8a2d\u5b9a\u3059\u308b\u304b\u3001\u3082\u3057\u304f\u306f\u30dc\u30bf\u30f3\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":317,"url":"http:\/\/nanoappli.com\/blog\/archives\/317","url_meta":{"origin":2781,"position":3},"title":"BackgroundWorker\u3067\u3001markdown\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u51e6\u7406\u3092\u6539\u5584","date":"2012\u5e741\u67088\u65e5","format":false,"excerpt":"\u524d\u56de\u307e\u3067\u306e\u4f5c\u696d\u3067\u3001\u753b\u9762\u3067\u5165\u529b\u3057\u305fMarkdown\u5f62\u5f0f\u30c6\u30ad\u30b9\u30c8\u3092\u305d\u306e\u5834\u3067\u30d7\u30ec\u30d3\u30e5\u30fc\u53ef\u80fd\u3068\u306a\u308a\u307e\u3057\u305f\u3002 \u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/20120108_01-500x371.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1274,"url":"http:\/\/nanoappli.com\/blog\/archives\/1274","url_meta":{"origin":2781,"position":4},"title":"C#\u306e\u30e9\u30e0\u30c0\u5f0f\u3092\u30c1\u30a7\u30fc\u30f3\u3055\u305b\u308b\u8a18\u6cd5\u304c\u4fbf\u5229!","date":"2012\u5e742\u67089\u65e5","format":false,"excerpt":"(\u3053\u306e\u8a18\u4e8b\u306f,Hidden Features of C#?\u3092\u53c2\u8003\u306b\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059) C#\u3067\u306f\u3001\u30d0\u30fc\u30b8\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6540,"url":"http:\/\/nanoappli.com\/blog\/archives\/6540","url_meta":{"origin":2781,"position":5},"title":"[Unity3D]uGUI\u3067\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u6642\u306e\u30cf\u30f3\u30c9\u30e9\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u767b\u9332\u3059\u308b","date":"2015\u5e744\u670812\u65e5","format":false,"excerpt":"Unity\u3067uGUI\u306e\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u306b\u5bfe\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\u3057\u305f\u3044\u6642\u306f\u3001 AddListene\u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2015\/04\/150412_1.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2781"}],"collection":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/comments?post=2781"}],"version-history":[{"count":8,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2781\/revisions"}],"predecessor-version":[{"id":2806,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2781\/revisions\/2806"}],"wp:attachment":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/media?parent=2781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/categories?post=2781"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/tags?post=2781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}