public IDataSource GetDataSource() { var activeWindowHandle = windowNativeApi.GetForegroundWindow(); var windowTitle = windowNativeApi.GetWindowTitle(activeWindowHandle); var windowIcon = GetWindowIcon(activeWindowHandle); var iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon); return(new DataSource(iconBytes, windowTitle)); }
public IDataSource GetDataSource() { var activeWindowHandle = windowNativeApi.GetForegroundWindow(); var windowTitle = windowNativeApi.GetWindowTitle(activeWindowHandle); lock (this) { byte[] iconBytes; if (dataSourceIconCache.ContainsKey(activeWindowHandle)) { iconBytes = dataSourceIconCache[activeWindowHandle]; } else { var windowIcon = GetWindowIcon(activeWindowHandle); iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon); dataSourceIconCache.Add(activeWindowHandle, iconBytes); } var dataSource = new DataSource(iconBytes, windowTitle); return(dataSource); } }