void _serverConnection_ConnectionClosed(object sender, EventArgs e) { _context.Post(new SendOrPostCallback(delegate(object state) { panel1.Enabled = false; splitContainer1.Enabled = false; _serverConnection = null; toolStripStatusLabelConnectionStatus.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NOTCONNECTED); checkRetry(); }), null); }
private void CloseConnection() { try { listBox1.Items.Clear(); panel1.Enabled = false; splitContainer1.Enabled = false; toolStripStatusLabelConnectionStatus.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NOTCONNECTED); checkBoxCanFollow.Checked = false; if (_serverConnection != null) { _serverConnection.ConnectionClosed -= new EventHandler<EventArgs>(_serverConnection_ConnectionClosed); _serverConnection.DataReceived -= new EventHandler<EventArgs>(_serverConnection_DataReceived); _serverConnection.Dispose(); _serverConnection = null; } checkRetry(); } catch { } }
public void UpdateView() { if (_serverConnection == null) { try { panel1.Enabled = false; splitContainer1.Enabled = false; toolStripStatusLabelConnectionStatus.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CONNECTING); TcpClient tcpClient = new TcpClient(); //then intialize _serverConnection = new ServerConnection(tcpClient); _serverConnection.ConnectionClosed += new EventHandler<EventArgs>(_serverConnection_ConnectionClosed); _serverConnection.DataReceived += new EventHandler<EventArgs>(_serverConnection_DataReceived); _serverConnection.Start(); ChatMessage msg = new ChatMessage(); msg.ID = _id; msg.Name = "signon"; msg.Room = _room; msg.Parameters.Add("username", Core.GeocachingComAccount.AccountName); msg.Parameters.Add("token", Core.GeocachingComAccount.APIToken); _serverConnection.SendData(msg.ChatMessageData); } catch { CloseConnection(); } } }