/// <summary> /// Returns whether a database connection can be established using the specified database connection string thru the specified synchronization result. /// </summary> /// <param name="result">Synchronization result from invoked BeginTryConnect method</param> /// <returns></returns> public static bool EndTryConnect(IAsyncResult result) { bool _connected = false; if (_delegatetable.ContainsKey(result)) { InvokingDelegate _invoker = (InvokingDelegate)_delegatetable[result]; if (_invoker.InvokedThruConnectionString) { Func <string, bool> _delegate = (Func <string, bool>)_invoker.Invoker; _connected = _delegate.EndInvoke(result); try { _delegate = null; } catch { } } else { Func <IDbConnection, bool> _delegate = (Func <IDbConnection, bool>)_invoker.Invoker; _connected = _delegate.EndInvoke(result); try { _delegate = null; } catch { } } _delegatetable.Remove(result); } return(_connected); }
/// <summary> /// Returns a asynchronization of the CanConnect function. Result can then be returned by calling EndTryConnect after the asynchronization is completed. /// </summary> /// <param name="connectionstring">Database connection string.</param> /// <returns></returns> public static IAsyncResult BeginTryConnect(string connectionstring) { Func <string, bool> _delegate = new Func <string, bool>(CanConnect); InvokingDelegate _invoker = new InvokingDelegate(); _invoker.InvokedThruConnectionString = true; _invoker.Invoker = _delegate; IAsyncResult _result = _delegate.BeginInvoke(connectionstring, null, _delegate); _delegatetable.Add(_result, _invoker); return(_result); }
/// <summary> /// Returns a asynchronization of the CanConnect function. Result can then be returned by calling EndTryConnect after the asynchronization is completed. /// </summary> /// <param name="connection">Database connection object.</param> /// <returns>System.IAsyncResult generated from the CanConnect asynchronization.</returns> public static IAsyncResult BeginTryConnect(IDbConnection connection) { Func<IDbConnection, bool> _delegate = new Func<IDbConnection, bool>(CanConnect); InvokingDelegate _invoker = new InvokingDelegate(); _invoker.InvokedThruConnectionString = false; _invoker.Invoker = _delegate; IAsyncResult _result = _delegate.BeginInvoke(connection, null, _delegate); _delegatetable.Add(_result, _invoker); return _result; }