private static async Task ConnectAsync( this ConnectAsyncDelegate connectAsync, Action close, string host, int port, CancellationToken token) { token.ThrowIfCancellationRequested(); await connectAsync(host, port).WaitAsync(token); if (token.IsCancellationRequested) { close(); } token.ThrowIfCancellationRequested(); }
public static void Connect(TreeView tv, TreeNode connNode) { SSBIServer srv = (SSBIServer)connNode.Tag; if (!srv.HasLoggedIn) { if (GetLoginCredentials(srv)) { //toolStripStatusLabel1.Text = string.Format("Connecting to: {0}", srv.Name); connNode.ForeColor = Color.Gray; srv.IsTryingToConnect = true; connNode.Tag = srv; connNode.Text = srv.Name + " - Connecting"; ConnectAsyncDelegate cd = new ConnectAsyncDelegate(ConnectAsync); IAsyncResult iar = cd.BeginInvoke(srv, tv, connNode, null, cd); } } }