public IEnumerable <XEN_VM> GetVMs() { uint count, i, j; XenGuestAgentLib.XenVmInfo xvic = null; try { count = xgsc.QueryVms(); if (count > 20) { throw new Exception("hack hack hack"); } } catch (Exception e) { log.Debug("Exception reading VMS information from XenGuestServices", e); yield break; } for (i = 0; i < count; i++) { XEN_VM xenvm = new XEN_VM(); MemoryStream ms; Array arr; Bitmap blueImage; try { xvic = xgsc.GetVmObject(i); } catch (Exception e) { log.Debug("Exception reading VMS information at index: " + i, e); yield break; } if (xvic == null) { log.Debug("No VM object returned for index: " + i); yield break; } xenvm.uuid = xvic.GetUuid(); xenvm.name = xvic.GetName(); xenvm.domid = xvic.GetDomId(); xenvm.slot = xvic.GetSlot(); xenvm.hidden = xvic.IsHidden(); xenvm.uivm = xvic.IsUivm(); xenvm.showSwitcher = xvic.IsSwitcherShown(); if (xvic.HasImage()) { ms = new MemoryStream(); arr = xvic.GetImage(); for (j = 0; j < (uint)arr.GetLength(0); j++) { ms.WriteByte((byte)arr.GetValue(j)); } xenvm.image = Image.FromStream(ms); } else { blueImage = (Bitmap)Properties.Resources.Blue_VM.Clone(); xenvm.image = blueImage; } Marshal.ReleaseComObject(xvic); xvic = null; yield return(xenvm); } }