         chatHubConnection = HubConnection(url: URL(string:"http://localhost:5000/chat")!, query: "")
         chatHubConnection!.delegate = chatHubConnectionDelegate
         chatHubConnection!.on(method: "NewMessage", callback: {args in
-            self.messages.append("\(args[0]!): \(args[1]!)")
+            self.dispatchQueue.sync {
+                self.messages.append("\(args[0]!): \(args[1]!)")
+            }
             self.appendMessage()
 
         })

    }

    func numberOfRows(in tableView: NSTableView) -> Int {
        return messages.count
    }

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {


    func appendMessage() {
        self.chatTableView.beginUpdates()
        let index = IndexSet(integer: self.chatTableView.numberOfRows)
        self.chatTableView.insertRows(at: index)
        self.chatTableView.endUpdates()
        self.chatTableView.scrollRowToVisible(self.chatTableView.numberOfRows - 1)
