private SwitchManager() { _log.Info("Initializing SwitchManager..."); _switchChanges = new ConcurrentQueue <Switch>(); //need to load the switch driver dynamically. //_driver = new IpacDriver(getSwitchesForGame()); //_driver = new KeyCatcherForm(58); #if USEARDUINO //TODO: Load the com port from app.config _driver = new SolenoidArduino("COM6", SwitchConstants.GetAllSwitchesForGame(), new Action <List <Switch> >(enqueueSwitchChanges)); #else //_driver = new ButtonForm(SwitchConstants.GetAllSwitchesForGame(), new Action<List<Switch>>(switchChangedHandler)); _driver = new ButtonForm(SwitchConstants.GetAllSwitchesForGame(), new Action <List <Switch> >(enqueueSwitchChanges)); #endif //This task just publishes the switch changes received from the driver. _cancelTokenSource = new CancellationTokenSource(); //used to stop the task in dispose _switchChangesHandleTask = new Task(() => handleSwitchChangesTask(_cancelTokenSource.Token), _cancelTokenSource.Token, TaskCreationOptions.LongRunning); _switchChangesHandleTask.Start(); }
private SwitchManager() { _log.Info("Initializing SwitchManager..."); _switchChanges = new ConcurrentQueue<Switch>(); //need to load the switch driver dynamically. //_driver = new IpacDriver(getSwitchesForGame()); //_driver = new KeyCatcherForm(58); #if USEARDUINO //TODO: Load the com port from app.config _driver = new SolenoidArduino("COM6", SwitchConstants.GetAllSwitchesForGame(), new Action<List<Switch>>(enqueueSwitchChanges)); #else //_driver = new ButtonForm(SwitchConstants.GetAllSwitchesForGame(), new Action<List<Switch>>(switchChangedHandler)); _driver = new ButtonForm(SwitchConstants.GetAllSwitchesForGame(), new Action<List<Switch>>(enqueueSwitchChanges)); #endif //This task just publishes the switch changes received from the driver. _cancelTokenSource = new CancellationTokenSource(); //used to stop the task in dispose _switchChangesHandleTask = new Task(() => handleSwitchChangesTask(_cancelTokenSource.Token), _cancelTokenSource.Token, TaskCreationOptions.LongRunning); _switchChangesHandleTask.Start(); }