/// <summary> /// Connects the dashboard to the robot with the given address. /// </summary> /// <param name="connectAddress">The address to try connecting to.</param> /// <param name="functionToExecuteOnConnect">The function to call IMMEDIATELY when the robot is connected. /// Faster than waiting for the event to run.</param> public async void Connect(string connectAddress, Action <bool> functionToExecuteOnConnect = null) { IsConnecting = true; // Make it a string and trim so this works properly ConnectedAddress = connectAddress.ToString(); ConnectedAddress = ConnectedAddress.Trim(); CancellationTokenSource cts = new CancellationTokenSource(); bool connected = await Task.Run <bool>(() => ConnectAsync(cts.Token)); // Call the action that was requested to be executed on connect, if it's not null functionToExecuteOnConnect?.Invoke(connected); IsConnecting = false; ConnectionEvent?.Invoke(this, IsConnected); // Populate the Tables dictionary if (connected) { await Task.Run(PopulateTablesAsync); // Call changed events CallChangedMethodsForAll(); } }