本文整理汇总了C#中System.Management.ManagementOperationObserver.GetNewGetSink方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementOperationObserver.GetNewGetSink方法的具体用法?C# ManagementOperationObserver.GetNewGetSink怎么用?C# ManagementOperationObserver.GetNewGetSink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementOperationObserver
的用法示例。
在下文中一共展示了ManagementOperationObserver.GetNewGetSink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public void Get(ManagementOperationObserver watcher)
{
this.Initialize(false);
if (this.path == null || this.path.Path.Length == 0)
{
throw new InvalidOperationException();
}
else
{
if (watcher != null)
{
IWbemServices wbemServices = this.scope.GetIWbemServices();
ObjectGetOptions objectGetOption = ObjectGetOptions._Clone(this.options);
WmiGetEventSink newGetSink = watcher.GetNewGetSink(this.scope, objectGetOption.Context, this);
if (watcher.HaveListenersForProgress)
{
objectGetOption.SendStatus = true;
}
SecurityHandler securityHandler = this.scope.GetSecurityHandler();
int objectAsync_ = this.scope.GetSecuredIWbemServicesHandler(wbemServices).GetObjectAsync_(this.path.RelativePath, objectGetOption.Flags, objectGetOption.GetContext(), newGetSink.Stub);
if (securityHandler != null)
{
securityHandler.Reset();
}
if (objectAsync_ < 0)
{
watcher.RemoveSink(newGetSink);
if (((long)objectAsync_ & (long)-4096) != (long)-2147217408)
{
Marshal.ThrowExceptionForHR(objectAsync_);
}
else
{
ManagementException.ThrowWithExtendedInfo((ManagementStatus)objectAsync_);
return;
}
}
return;
}
else
{
throw new ArgumentNullException("watcher");
}
}
}
示例2: Get
//******************************************************
//Get
//******************************************************
/// <summary>
/// <para> Binds to the management object asynchronously.</para>
/// </summary>
/// <param name='watcher'>The object to receive the results of the operation as events.</param>
/// <remarks>
/// <para>The method will issue the request to get the object
/// and then will immediately return. The results of the operation will then be
/// delivered through events being fired on the watcher object provided.</para>
/// </remarks>
/// <example>
/// <code lang='C#'>ManagementObject o = new ManagementObject("MyClass.Name='abc'");
///
/// //Set up handlers for asynchronous get
/// MyHandler h = new MyHandler();
/// ManagementOperationObserver ob = new ManagementOperationObserver();
/// ob.Completed += new CompletedEventHandler(h.Done);
///
/// //Get the object asynchronously
/// o.Get(ob);
///
/// //Wait until operation is completed
/// while (!h.Completed)
/// System.Threading.Thread.Sleep (1000);
///
/// //Here we can use the object
/// Console.WriteLine(o["SomeProperty"]);
///
/// public class MyHandler
/// {
/// private bool completed = false;
///
/// public void Done(object sender, CompletedEventArgs e) {
/// Console.WriteLine("async Get completed !");
/// completed = true;
/// }
///
/// public bool Completed {
/// get {
/// return completed;
/// }
/// }
/// }
/// </code>
/// <code lang='VB'>Dim o As New ManagementObject("MyClass.Name=""abc""")
///
/// 'Set up handlers for asynchronous get
/// Dim h As New MyHandler()
/// Dim ob As New ManagementOperationObserver()
/// ob.Completed += New CompletedEventHandler(h.Done)
///
/// 'Get the object asynchronously
/// o.Get(ob)
///
/// 'Wait until operation is completed
/// While Not h.Completed
/// System.Threading.Thread.Sleep(1000)
/// End While
///
/// 'Here we can use the object
/// Console.WriteLine(o("SomeProperty"))
///
/// Public Class MyHandler
/// Private _completed As Boolean = false;
///
/// Public Sub Done(sender As Object, e As EventArrivedEventArgs)
/// Console.WriteLine("async Get completed !")
/// _completed = True
/// End Sub
///
/// Public ReadOnly Property Completed() As Boolean
/// Get
/// Return _completed
/// End Get
/// End Property
/// End Class
/// </code>
/// </example>
public void Get(ManagementOperationObserver watcher)
{
Initialize ( false ) ;
if ((null == path) || (path.Path.Length==0))
throw new InvalidOperationException();
else if (null == watcher)
throw new ArgumentNullException("watcher");
else
{
IWbemServices wbemServices = scope.GetIWbemServices();
ObjectGetOptions o = ObjectGetOptions._Clone(options);
WmiGetEventSink sink = watcher.GetNewGetSink(
scope,
o.Context,
this);
// If someone has registered for progress, make sure we flag it
//.........这里部分代码省略.........