/* Disconnects from, then reconnects to the proxy and then calls the callback. Blocking function */ public bool reconnectToProxy(string ip, int port, ReconnectionAttemptCallback callback) { ReconnectionAttemptCallback realCallback = null; realCallback = delegate(bool success) { callback(success); ReconnectionAttemptEvent -= realCallback; }; ReconnectionAttemptEvent += realCallback; bool res = reconnectToProxy(ip, port); if (ReconnectionAttemptEvent != null) { ReconnectionAttemptEvent(res); } return(res); }
/* Disconnects from, then reconnects to the proxy in a new thread and then calls the callback from this thread. Non-Blocking function */ public void reconnectToProxyAsync(string ip, int port, ReconnectionAttemptCallback callback) { ReconnectionAttemptCallback realCallback = null; realCallback = delegate(bool success) { callback(success); ReconnectionAttemptEvent -= realCallback; }; ReconnectionAttemptEvent += realCallback; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { bool res = reconnectToProxy(ip, port); if (ReconnectionAttemptEvent != null) { ReconnectionAttemptEvent(res); } }); bw.RunWorkerAsync(); }