//methods controls private void ActionDevice(Func <DeviceCapture, DeviceState> task) { int key; if (list_view_devices.SelectedItems.Count > 0) { var item = list_view_devices.SelectedItems[0]; key = (int)item.Tag; item.ImageIndex = (int)task(DeviceController.GetDevice(key)); } else { key = DeviceController.selected_device; DeviceController.ChangeIconState(key, task(DeviceController.GetDevice(key))); } EnableDeviceButtons(); }