public async Task StartAsync() { if (!_started) { // create the connection using the .NET SignalR client _hubConnection = new HubConnectionBuilder() .WithUrl(_hubUrl) .Build(); Console.WriteLine("ChatClient: calling Start()"); // add handler for receiving messages _hubConnection.On <Message>(MessageFunctions.RECEIVE, (message) => { HandleReceiveMessage(message); }); _hubConnection.On(MessageFunctions.USEREVENT, () => { UserEvent?.Invoke(this, EventArgs.Empty); }); // start the connection await _hubConnection.StartAsync(); Console.WriteLine("ChatClient: Start returned"); _started = true; // register user on hub to let other clients know they've joined await _hubConnection.SendAsync(MessageFunctions.REGISTER, _username); } }
// Method to invoke event public void OnUserEvent() { //if(UserEvent != null) //{ UserEvent.Invoke(); //} }
public void RaiseEvent(object sender, string eventType) { UserEvent?.Invoke(sender, eventType); }
private void button1_Click(object sender, EventArgs e) { UserEvent?.Invoke(textBox1.Text.Trim(), textBox2.Text.Trim()); this.Close(); }
protected virtual void RaiseUserEvent(TokenEventArgs e) { UserEvent?.Invoke(this, e); }
public void UserLeave(NetworkUser user) { roomUsers.Remove(user); userLeaveEvent.Invoke(user); }
public void UserJoin(NetworkUser user) { roomUsers.Add(user); userJoinEvent.Invoke(user); }