C# 使用VMWare.vim.dll克隆VM后如何等待任务?

C# 使用VMWare.vim.dll克隆VM后如何等待任务?,c#,vmware,powercli,C#,Vmware,Powercli,我正在开发一个web界面,用于管理vsphere Esx 5.5上的虚拟机。我的程序是用.NETWebForms(不是MVC)开发的 我关注jeffpaton的帖子(使用VMware.Vim),这对我很有帮助(感谢你,Jeff) 但现在我对这个问题束手无策。我不知道克隆VM后如何等待任务。我的网站使用vmware.vim向vsphere Esx启动vsphere命令。我需要知道Vpsher什么时候完成了启动另一条指令的工作 我尝试使用PropertyCollector,但不知道如何使用它: 我写

我正在开发一个web界面,用于管理vsphere Esx 5.5上的虚拟机。我的程序是用.NETWebForms(不是MVC)开发的

我关注jeffpaton的帖子(使用VMware.Vim),这对我很有帮助(感谢你,Jeff)

但现在我对这个问题束手无策。我不知道克隆VM后如何等待任务。我的网站使用vmware.vim向vsphere Esx启动vsphere命令。我需要知道Vpsher什么时候完成了启动另一条指令的工作

我尝试使用PropertyCollector,但不知道如何使用它:

我写了这篇文章,但没有成功:

这是我的代码的一部分,但我被阻止了。我使用jeffpaton函数

using VMware.Vim;
...
VimClient client;
string serverUrl = "..."
client.Connect("https://" + serverUrl + "/sdk");
client.Login(userLogin, userPassword);
...
ManagedObjectReference cloneTask_MoRef = null;

//1 waiting the cloning task
cloneTask_MoRef = sourceVm.cloneVM_Task(sourceVm.Parent, "cloneName", mySpec);

if (cloneTask_MoRef == null) {
 //error
}else
{
    PropertyCollector pc = new PropertyCollector(client, cloneTask_MoRef);

    PropertyFilterSpec[] pfs = null;
    RetrieveOptions ro = new RetrieveOptions();
    RetrieveResult rResult = new RetrieveResult();


    //PropertySpec
    //pc.CreateFilter(pfs, true);
    //rResult = pc.RetrievePropertiesEx(pfs,ro);
    //

   //2 PowerOn the CloneVM                                                       
   cloneVM = this.vimClientTools.getVirtualMachines(selectedDC, cloneName)[0];

   //3 waiting the powerOn Task...

      //What could i do to know if the task is over or in progress ? :-(
我需要一些帮助。如果某人有一个开始的建议


谢谢大家

这可能太晚了,但现在开始

VimClient有一个WaitForTask方法

client.WaitForTask(cloneTask_MoRef);
或者,您可以获取任务并查看其进度

var task = (Task) client.GetView(cloneTask_MoRef, null);

while (task.Info.State != TaskInfoState.success)
{
    Thread.Sleep(5000);
    task.UpdateViewData();
    if (task.Info.State == TaskInfoState.error)
        throw new Exception($"The clone failed: {task.Info.Error.LocalizedMessage}");

    Console.WriteLine(task.Info.Progress);
}