/// <summary> /// Returns a Wox.Plugin.Result object corresponding to this machine. /// </summary> /// <param name="machine">The machine to resultify</param> public static Result ToResult(this VirtualBoxApi.IMachine machine) { return(new Result() { Title = machine.Name, SubTitle = machine.State.ToDisplayString(), IcoPath = Main.IconPath, Action = context => { // the machine cannot be launched if it's already online if (machine.Online()) { return false; } var session = new VirtualBoxApi.Session(); var progress = machine.LaunchVMProcess(session, "gui", string.Empty); /* * Although everything appears to work fine if we don't unlock the machine after launching, * the VirtualBox SDK reference (http://download.virtualbox.org/virtualbox/SDKRef.pdf) says * that we must unlock it (see the documentation of IMachine::launchVMProcess()). We do this * asynchronously to keep the Wox UI responsive. */ Task.Run(() => { progress.WaitForCompletion(10000); // 10s if (progress.ResultCode == 0) { session.UnlockMachine(); } }); return true; } }); }