本文整理汇总了C#中System.Management.InvokeMethodOptions.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# InvokeMethodOptions.Clone方法的具体用法?C# InvokeMethodOptions.Clone怎么用?C# InvokeMethodOptions.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.InvokeMethodOptions
的用法示例。
在下文中一共展示了InvokeMethodOptions.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeMethod
public void InvokeMethod(ManagementOperationObserver watcher, string methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
{
InvokeMethodOptions invokeMethodOption;
if (this.path == null || this.path.Path.Length == 0)
{
throw new InvalidOperationException();
}
else
{
if (watcher != null)
{
if (methodName != null)
{
this.Initialize(false);
if (options != null)
{
invokeMethodOption = (InvokeMethodOptions)options.Clone();
}
else
{
invokeMethodOption = new InvokeMethodOptions();
}
InvokeMethodOptions invokeMethodOption1 = invokeMethodOption;
if (watcher.HaveListenersForProgress)
{
invokeMethodOption1.SendStatus = true;
}
WmiEventSink newSink = watcher.GetNewSink(this.scope, invokeMethodOption1.Context);
SecurityHandler securityHandler = this.scope.GetSecurityHandler();
IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
if (inParameters != null)
{
wbemClassObjectFreeThreaded = inParameters.wbemObject;
}
int num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecMethodAsync_(this.path.RelativePath, methodName, invokeMethodOption1.Flags, invokeMethodOption1.GetContext(), wbemClassObjectFreeThreaded, newSink.Stub);
if (securityHandler != null)
{
securityHandler.Reset();
}
if (num < 0)
{
watcher.RemoveSink(newSink);
if (((long)num & (long)-4096) != (long)-2147217408)
{
Marshal.ThrowExceptionForHR(num);
}
else
{
ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
return;
}
}
return;
}
else
{
throw new ArgumentNullException("methodName");
}
}
else
{
throw new ArgumentNullException("watcher");
}
}
}
示例2: InvokeMethod
/// <summary>
/// <para>Invokes a method on the object, asynchronously.</para>
/// </summary>
/// <param name='watcher'>A <see cref='System.Management.ManagementOperationObserver'/> used to handle the asynchronous execution's progress and results.</param>
/// <param name=' methodName'>The name of the method to be executed.</param>
/// <param name=' inParameters'><para>A <see cref='System.Management.ManagementBaseObject'/> containing the input parameters for the method.</para></param>
/// <param name=' options'>An <see cref='System.Management.InvokeMethodOptions'/> containing additional options used to execute the method.</param>
/// <remarks>
/// <para>The method invokes the specified method execution and then
/// returns. Progress and results are reported through events on the <see cref='System.Management.ManagementOperationObserver'/>.</para>
/// </remarks>
public void InvokeMethod(
ManagementOperationObserver watcher,
string methodName,
ManagementBaseObject inParameters,
InvokeMethodOptions options)
{
if ((null == path) || (path.Path.Length==0))
throw new InvalidOperationException();
else if (null == watcher)
throw new ArgumentNullException("watcher");
else if (null == methodName)
throw new ArgumentNullException("methodName");
else
{
Initialize ( false ) ;
InvokeMethodOptions o = (null != options) ?
(InvokeMethodOptions) options.Clone() : new InvokeMethodOptions();
// If someone has registered for progress, make sure we flag it
if (watcher.HaveListenersForProgress)
o.SendStatus = true;
WmiEventSink sink = watcher.GetNewSink(scope, o.Context);
SecurityHandler securityHandler = null;
int status = (int)ManagementStatus.NoError;
securityHandler = scope.GetSecurityHandler();
IWbemClassObjectFreeThreaded inParams = null;
if (null != inParameters)
inParams = inParameters.wbemObject;
status = scope.GetSecuredIWbemServicesHandler( scope.GetIWbemServices() ).ExecMethodAsync_(
path.RelativePath,
methodName,
o.Flags,
o.GetContext(),
inParams,
sink.Stub );
if (securityHandler != null)
securityHandler.Reset();
if (status < 0)
{
watcher.RemoveSink(sink);
if ((status & 0xfffff000) == 0x80041000)
ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
else
Marshal.ThrowExceptionForHR(status);
}
}
}