示例#1
0
        /// <summary>
        /// Load data asyncronously.
        /// </summary>
        /// <param name="command">The complete command</param>
        /// <param name="callback">The callback action handler.</param>
        /// <param name="callbackException">The callback action exception handler.</param>
        /// <param name="state">The action state.</param>
        public static async void ExecuteQuery(DbCommand command,
                                              Action <Nequeo.Threading.AsyncOperationResult <DataTable> > callback,
                                              Action <Nequeo.Threading.AsyncOperationResult <System.Exception> > callbackException, object state = null)
        {
            // Check to see if the critical parameters
            // have been set, throw exception on each.
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            AsyncLoadDataTable ret  = new AsyncLoadDataTable(command, null, null);
            Task <DataTable>   data = Task <DataTable> .Factory.FromAsync(ret.BeginLoad(), ret.EndLoad);

            DataTable dataTableAsyncResult = await data;

            if (callback != null)
            {
                callback(new Nequeo.Threading.AsyncOperationResult <DataTable>(dataTableAsyncResult, state, "ExecuteQuery"));
            }

            if (callbackException != null)
            {
                callbackException(new Nequeo.Threading.AsyncOperationResult <System.Exception>(ret.Exception, state, "ExecuteQuery"));
            }
        }
示例#2
0
        /// <summary>
        /// Load data.
        /// </summary>
        /// <param name="command">The complete command</param>
        /// <returns>The data table containing the data.</returns>
        public static DataTable ExecuteQuery(DbCommand command)
        {
            // Check to see if the critical parameters
            // have been set, throw exception on each.
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // Create the new async operation
            AsyncLoadDataTable ret  = new AsyncLoadDataTable(command, null, null);
            DataTable          data = ret.FuncAsyncLoad();

            // If an error occures then thow the excption.
            if (ret.Exception != null)
            {
                throw new Exception(ret.Exception.Message, ret.Exception.InnerException);
            }

            return(data);
        }