示例#1
0
        /// <summary>
        /// 同步模式:处理
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override object DoExecuteMessageRequest(string serviceName, WQMessage msg, bool async)
        {
            //1. 保存DB,返回msg.TranscactionID
            //2. 异步调用同步方法
            //3. 开启守护线程修补失败的
            Log.Write(LogAction.Info, className, "DoExecuteMessageRequest", serviceName, -1, string.Format(startFormat, serviceName, msg.TransactionID));
            Routing routing = Routing(serviceName, msg);
            if (null == routing || routing.EmptyHandlerName.Length > 0)
            {
                return EmptyRouting(serviceName, msg, async);
            }
            int rtn = -1;
            msg.ServiceName = serviceName;
            long pidx = routing.ParentGroupIndex;
            long idx = routing.GroupIndex;
            rtn = MessageDao.Save(serviceName, msg, (int)DealStatus.Dealing, pidx, idx);
            Log.Write(LogAction.Info, className, "DoExecuteMessageRequest", serviceName, -1, msg.TransactionID + ",保存消息返回值:" + rtn);
            if (rtn > 0)
            {
                AsyncDelegate ad = new AsyncDelegate(AsyncExecute);
                ad.BeginInvoke(serviceName, pidx, idx, msg, null, null);
            }
            return (rtn > 0);

        }
        public void transferDidStart(Transfer t)
        {
            AsyncDelegate d = delegate
            {
                View.TransferStatus        = TransferStatus.InProgress;
                View.ProgressIndeterminate = true;
                Progress(String.Empty);
                View.StatusText = String.Empty;
            };

            invoke(new SimpleDefaultMainAction(this, d));
        }
示例#3
0
        /// <summary>
        /// 异步调用完成时执行回调方法
        /// 不会阻塞调用线程
        /// </summary>
        private void Test3()
        {
            //输出主线程ID
            Console.WriteLine("主线程ID:{0}", Thread.CurrentThread.ManagedThreadId);
            //创建委托
            AsyncDelegate asyncDel  = new AsyncDelegate(TestMethod);
            int           nThreadID = 0;

            //异步执行TestMethod方法,使用回调函数并传入state参数
            IAsyncResult result = asyncDel.BeginInvoke(3000, out nThreadID,
                                                       new AsyncCallback(AsyncCallCompleted), "测试参数传递");
        }
示例#4
0
        /// <summary>
        /// Notifies PM with a message.
        /// </summary>
        /// <param name="msg">Message sent to PM.</param>
        public void NotifyPM(string msg)
        {
            if (repInfo.LoggingLvl.Equals("full"))
            {
                PMServices service = getPMServices();

                AsyncDelegate RemoteDel = new AsyncDelegate(service.SendToLog);

                // Call delegate to remote method
                IAsyncResult RemAr = RemoteDel.BeginInvoke(msg, null, null);
            }
        }
示例#5
0
        /// <summary>
        /// Finishes asynchronous execution of a SQL statement, returning the requested
        /// <see cref="MySqlDataReader"/>.
        /// </summary>
        /// <param name="result">The <see cref="IAsyncResult"/> returned by the call to
        /// <see cref="BeginExecuteReader()"/>.</param>
        /// <returns>A <b>MySqlDataReader</b> object that can be used to retrieve the requested rows. </returns>
        public MySqlDataReader EndExecuteReader(IAsyncResult result)
        {
            result.AsyncWaitHandle.WaitOne();
            AsyncDelegate c = caller;

            caller = null;
            if (thrownException != null)
            {
                throw thrownException;
            }
            return((MySqlDataReader)c.EndInvoke(result));
        }
示例#6
0
        /// <summary>
        /// Initiates the asynchronous execution of the SQL statement or stored procedure
        /// that is described by this <see cref="MySqlCommand"/>.
        /// </summary>
        /// <param name="callback">
        /// An <see cref="AsyncCallback"/> delegate that is invoked when the command's
        /// execution has completed. Pass a null reference (<b>Nothing</b> in Visual Basic)
        /// to indicate that no callback is required.</param>
        /// <param name="stateObject">A user-defined state object that is passed to the
        /// callback procedure. Retrieve this object from within the callback procedure
        /// using the <see cref="IAsyncResult.AsyncState"/> property.</param>
        /// <returns>An <see cref="IAsyncResult"/> that can be used to poll or wait for results,
        /// or both; this value is also needed when invoking <see cref="EndExecuteNonQuery"/>,
        /// which returns the number of affected rows. </returns>
        public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObject)
        {
            if (caller != null)
            {
                Throw(new MySqlException(Resources.UnableToStartSecondAsyncOp));
            }

            caller      = new AsyncDelegate(AsyncExecuteWrapper);
            asyncResult = caller.BeginInvoke(2, CommandBehavior.Default,
                                             callback, stateObject);
            return(asyncResult);
        }
示例#7
0
        /// <summary>
        /// Finishes asynchronous execution of a SQL statement.
        /// </summary>
        /// <param name="asyncResult">The <see cref="IAsyncResult"/> returned by the call
        /// to <see cref="BeginExecuteNonQuery()"/>.</param>
        /// <returns></returns>
        public int EndExecuteNonQuery(IAsyncResult asyncResult)
        {
            asyncResult.AsyncWaitHandle.WaitOne();
            AsyncDelegate c = caller;

            caller = null;
            if (thrownException != null)
            {
                throw thrownException;
            }
            return((int)c.EndInvoke(asyncResult));
        }
            public override void transferWillStart()
            {
                AsyncDelegate d = delegate
                {
                    _view.TransferStatus        = TransferStatus.InProgress;
                    _view.ProgressIndeterminate = true;
                    _controller.SetProgressText();
                    _controller.SetStatusText();
                };

                _controller.invoke(new SimpleDefaultMainAction(_controller, d));
            }
示例#9
0
        private static void MSMQCallbackMethod(IAsyncResult ar)
        {
            AsyncDelegate dlgt = (AsyncDelegate)ar.AsyncState;

            bool returnValue = dlgt.EndInvoke(ar);

            //傳送失敗
            if (!returnValue)
            {
                //do some thing here
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            IObservable <string> o = LongRunningOperationAsync("Task1");

            using (var sub = OutputToConsole(o))
            {
                Sleep(TimeSpan.FromSeconds(2));
            };
            WriteLine(" ---------------- ");

            Task <string> t = LongRunningOperationTaskAsync("Task2");

            using (var sub = OutputToConsole(t.ToObservable()))
            {
                Sleep(TimeSpan.FromSeconds(2));
            };
            WriteLine(" ---------------- ");

            AsyncDelegate asyncMethod = LongRunningOperation;

            // marked as obsolete, use tasks instead
            Func <string, IObservable <string> > observableFactory =
                Observable.FromAsyncPattern <string, string>(
                    asyncMethod.BeginInvoke, asyncMethod.EndInvoke);

            o = observableFactory("Task3");
            using (var sub = OutputToConsole(o))
            {
                Sleep(TimeSpan.FromSeconds(2));
            };
            WriteLine(" ---------------- ");

            o = observableFactory("Task4");
            AwaitOnObservable(o).Wait();
            WriteLine(" ---------------- ");

            using (var timer = new Timer(1000))
            {
                var ot = Observable.
                         FromEventPattern <ElapsedEventHandler, ElapsedEventArgs>(
                    h => timer.Elapsed += h,
                    h => timer.Elapsed -= h);
                timer.Start();

                using (var sub = OutputToConsole(ot))
                {
                    Sleep(TimeSpan.FromSeconds(5));
                }
                WriteLine(" ---------------- ");
                timer.Stop();
            }
        }
示例#11
0
        public void Crash(string opx, string rep)
        {
            RepServices repServ = getReplicaServiceFromProcessname(opx, rep);

            //Asynchronous call without callback
            // Create delegate to remote method
            AsyncDelegate RemoteDel = new AsyncDelegate(repServ.Crash);

            // Call delegate to remote method
            IAsyncResult RemAr = RemoteDel.BeginInvoke(null, null);

            SendToLog("Crash " + opx + " " + rep);
        }
		private void btn_async_Click(object sender, EventArgs e)
		{
			ad = new AsyncDelegate(t.GetTime);
			AsyncCallback acb = new AsyncCallback(CB);
			if (chk_sec.Checked)
			{
				ad.BeginInvoke(true, acb, null);
			}
			else
			{
				ad.BeginInvoke(false, acb, null);
			}
		}
示例#13
0
 public void CloseSock()
 {
     try
     {
         Lisen_sock.Close();
         dlgt     = null;
         dlgtShow = null;
     }
     catch (Exception)
     {
         ;
     }
 }
示例#14
0
 private static Task ExecuteDelegateAsync(AsyncDelegate asyncDelegate)
 {
     try
     {
         return(asyncDelegate());
     }
     catch (Exception ex)
     {
         var tcs = new TaskCompletionSource <int>();
         tcs.SetException(ex);
         return(tcs.Task);
     }
 }
示例#15
0
 /// <summary>
 /// Executes the given AsyncDelegate in the SynchronizationContext associated with this
 /// instance of async class
 /// </summary>
 /// <param name="ad">AsyncDelegate object</param>
 public void ExecuteInSychronizationContext(AsyncDelegate ad)
 {
     if (_synchronizationContext != null)
     {
         _synchronizationContext.Send(
             Delegate.CreateDelegate(typeof(SendOrPostCallback), ad.Method) as SendOrPostCallback,
             null);
     }
     else
     {
         throw new InvalidOperationException(
                   "SynchronizationContext object is not available to execute the supplied code");
     }
 }
示例#16
0
 public void Deserialization()
 {
     // Organize file access
     while (true)
     {
         if (state)
         {
             state = false;
             AsyncDelegate action      = AsyncDeserialization;
             IAsyncResult  asyncResult = action.BeginInvoke(null, null);
             break;
         }
     }
 }
示例#17
0
        private void View_StopEvent()
        {
            foreach (IProgressView progressView in View.SelectedTransfers)
            {
                Transfer transfer = GetTransferFromView(progressView);

                AsyncDelegate run     = transfer.cancel;
                AsyncDelegate cleanup = delegate {; };

                if (transfer.isRunning())
                {
                    Background(run, cleanup);
                }
            }
        }
示例#18
0
 /// <summary>
 /// 將可續列化的物件使用Message Queue傳送
 /// </summary>
 /// <param name="o">被傳送的物件</param>
 /// <param name="existingMachineName">MachineName</param>
 /// <param name="existingQueueName">QueueName</param>
 //public static void SendMesageQueue(object o, string existingMachineName, string existingQueueName)
 public void SendMesageQueue(object o, string existingMachineName, string existingQueueName)
 {
     if (!MessageQueue.Exists(existingMachineName + "\\" + existingQueueName))
     {
         MessageQueue.Create(existingMachineName + "\\" + existingQueueName);
         MSMQueue = new MessageQueue(existingMachineName + "\\" + existingQueueName);
         MSMQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
     }
     else
     {
         MSMQueue = new MessageQueue(existingMachineName + "\\" + existingQueueName);
     }
     MSMQueue.Formatter = new XmlMessageFormatter(new Type[] { o.GetType() });
     AsyncDelegate dlgt = new AsyncDelegate(Send);
     IAsyncResult  ar   = dlgt.BeginInvoke(o, new AsyncCallback(MSMQCallbackMethod), dlgt);
 }
示例#19
0
        /// <summary>
        /// 使用 EndInvoke阻塞调用线程,直到异步调用结束
        /// </summary>
        private void Test()
        {
            //输出主线程ID
            Console.WriteLine("主线程ID:{0}", Thread.CurrentThread.ManagedThreadId);
            //创建委托
            AsyncDelegate asyncDel  = new AsyncDelegate(TestMethod);
            int           nThreadID = 0;

            //异步执行TestMethod方法
            IAsyncResult result = asyncDel.BeginInvoke(3000, out nThreadID, null, null);

            //阻塞调用线程
            asyncDel.EndInvoke(out nThreadID, result);

            this.BeginInvoke(_delegate, new object[] { nThreadID.ToString() });
        }
示例#20
0
        void msgHandle(IAsyncResult ar)
        {
            AsyncDelegate dlgt  = (AsyncDelegate)ar.AsyncState;
            int           count = dlgt.EndInvoke(ar);
            string        str   = "";

            for (int i = 0; i < count && i < 5; i++)
            {
                str += CConsLog.mLogInfo[i] + " 时间:" + CConsLog.mLogTime[i].ToShortTimeString() + "\t\t";
            }
            labelRoll1.Invoke(new EventHandler(delegate
            {
                labelRoll1.Text = str;
            }));
            //labelRoll1.Refresh();
        }
        private static AsyncDelegate getAction()
        {
            AsyncDelegate action = null;

            foreach (SchedulerEntry entry in schedulerEntries)
            {
                if (entry.IsDue)
                {
                    action = entry.Action;
                    toBeRemoved.Add(entry);
                    break;
                }
            }

            return(action);
        }
示例#22
0
        private void CreateShapeFile(BaseControlGroup b, string state, string filePath)
        {
            string msg = string.Empty;

            ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
            ModelDataLine modelDataLine          = new ModelDataLine(); try

            {
                modelDataLine.DatabaseFilePath = filePath;
                System.Data.DataTable dtModel = CommonClass.ExcelToDataTable(filePath);
                DataSourceCommonClass.UpdateModelDataLineFromDataSet(b.Pollutant, modelDataLine, dtModel);

                switch (state)
                {
                case "baseline":
                    b.Base = null;
                    b.Base = modelDataLine;
                    break;

                case "control":
                    b.Control = null;
                    b.Control = modelDataLine;
                    break;
                }
                if (modelDataLine.ModelAttributes.Count == 0)
                {
                    msg = "Error reading files.";
                    return;
                }
                int           threadId = -1;
                AsyncDelegate asyncD   = new AsyncDelegate(AsyncCreateFile);
                IAsyncResult  ar       = asyncD.BeginInvoke(b, modelDataLine, state, out threadId, null, null);
                return;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return;
            }
            finally
            {
                if (msg != string.Empty)
                {
                    MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
示例#23
0
 public void BeginInvoke(AsyncDelegate del)
 {
     ControllerMainAction mainAction = new SimpleDefaultMainAction(this, del);
     try
     {
         if (!View.IsHandleCreated)
         {
             return;
         }
         View.BeginInvoke(new AsyncDelegate(mainAction.run), null);
     }
     catch (ObjectDisposedException)
     {
         //happens because there is no synchronization between the lifecycle of a form and callbacks of background threads.
         //catch silently
     }
 }
示例#24
0
        public static Task <TException> ExpectExceptionAsync <TException>(AsyncDelegate del, string exceptionMessage)
            where TException : Exception
        {
            var task = ExpectExceptionAsync <TException>(del);

            // Only check exception message on English build and OS, since some exception messages come from the OS
            // and will be in the native language.
            if (UnitTestHelper.EnglishBuildAndOS)
            {
                task = task.ContinueWith(res =>
                {
                    var ex = res.GetAwaiter().GetResult();
                    Assert.AreEqual(exceptionMessage, ex.Message, "Incorrect exception message.");
                    return(ex);
                });
            }
            return(task);
        }
示例#25
0
        public void BeginInvoke(AsyncDelegate del)
        {
            ControllerMainAction mainAction = new SimpleDefaultMainAction(this, del);

            try
            {
                if (!View.IsHandleCreated)
                {
                    return;
                }
                View.BeginInvoke(new AsyncDelegate(mainAction.run), null);
            }
            catch (ObjectDisposedException)
            {
                //happens because there is no synchronization between the lifecycle of a form and callbacks of background threads.
                //catch silently
            }
        }
示例#26
0
            public override void transferDidEnd()
            {
                AsyncDelegate d = delegate
                {
                    _view.TransferStatus     = TransferStatus.Complete;
                    _controller._messageText = null;
                    _controller.SetMessageText();
                    _controller.SetProgressText();
                    _controller.SetStatusText();
                    _view.TransferStatus = _controller._transfer.isComplete()
                                                                     ? TransferStatus.Complete
                                                                     : TransferStatus.Incomplete;
                    //todo
                    //filesPopup.itemAtIndex(new NSInteger(0)).setEnabled(transfer.getRoot().getLocal().exists());
                    _controller.UpdateOverallProgress();
                };

                _controller.invoke(new SimpleDefaultMainAction(_controller, d));
            }
示例#27
0
        public void Status()
        {
            foreach (string operator_id in repServices.Keys)
            {
                ArrayList array;
                repServices.TryGetValue(operator_id, out array);
                for (int i = 0; i < array.Count; i++)
                {
                    RepServices repS = (RepServices)array[i];

                    //Asynchronous call without callback
                    // Create delegate to remote method
                    AsyncDelegate RemoteDel = new AsyncDelegate(repS.Status);

                    // Call delegate to remote method
                    IAsyncResult RemAr = RemoteDel.BeginInvoke(null, null);
                }
            }
            SendToLog("Status");
        }
示例#28
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Potok nomer {Thread.CurrentThread.ManagedThreadId} na4al paboty");
            var asyncDelegate = new AsyncDelegate(Calculate);

            // var result = asyncDelegate.Invoke(10, 15);

            //async nomer 1
            //var asyncResult = asyncDelegate.BeginInvoke(10, 15, null, null);
            //while (!asyncResult.IsCompleted)
            //{
            //  Console.WriteLine("Жди");
            //  Thread.Sleep(800);
            //}
            //var result = asyncDelegate.EndInvoke(asyncResult);
            //Console.WriteLine("Rezylt = " + result);
            //async nomer 2
            asyncDelegate.BeginInvoke(10, 15, new AsyncCallback(CalculateCallback), null /*<--Тип Object*/);
            Console.ReadLine();
        }
        public void DoOldApm()
        {
            try
            {
                AsyncDelegate asyncDelegate = AsyncWaitThenReturn;

                IAsyncResult asyncResult = asyncDelegate.BeginInvoke(123, new TimeSpan(0, 0, 1), ar =>
                {
                    var result = asyncDelegate.EndInvoke(ar);
                    Console.WriteLine("result=" + result);
                }, null);

                SpinWait.SpinUntil(() => asyncResult.IsCompleted);

                Console.WriteLine("Async Delegate Finished.");
            }
            catch (PlatformNotSupportedException ex)
            {
                Console.WriteLine("PlatformNotSupportedException=" + ex);
            }
        }
示例#30
0
 private static void Execute(AsyncDelegate ad, ITask task, ThreadPool tp)
 {
     if (defaultThreadPool != null)
     {
         if (tp == null)
         {
             defaultThreadPool.Dispatch(task);
         }
         else
         {
             tp.Dispatch(task);
         }
     }
     else
     {
         throw new ApplicationException("Thread Pool used by AsynchronousCodeBlock class is closed. " +
                                        "Cannot execute any more asynchronous code blocks on default Thread pool. Please open the " +
                                        "Thread Pool used by AsynchronousCodeBlock class or supply your own Thread Pool object for " +
                                        "asynchronous code block");
     }
 }
示例#31
0
        public void prompt(Credentials credentials, string title, string reason, LoginOptions options)
        {
            AsyncDelegate d = delegate
            {
                View                = ObjectFactory.GetInstance <IPasswordPromptView>();
                View.Title          = title;
                View.Reason         = reason;
                View.OkButtonText   = LocaleFactory.localizedString("Unlock Vault", "Cryptomator");
                View.IconView       = IconCache.Instance.IconForName(options.icon(), 64);
                View.SavePassword   = false;
                View.ValidateInput += ValidateInputEventHandler;
                if (DialogResult.Cancel == View.ShowDialog(_browser.View))
                {
                    throw new LoginCanceledException();
                }
                credentials.setPassword(View.InputText);
                credentials.setSaved(View.SavePassword);
            };

            _browser.Invoke(d);
        }
示例#32
0
        public override void SubscribeBidAskBook(ASecurity s, int level)
        {
            //异步执行前,保存记录
            long reqId = _requestId++;

            this.htSubscribe.Add(reqId, true);

            //异步调用
            AsyncDelegate dlg;

            switch (s.category)
            {
            case SecurityCategory.STOCK:
            case SecurityCategory.ETF:
                this.htSubscribedStocks.Add(s.code, s.bidaskbook);
                this.addSubscribedStocks(s.code);
                if (!isLoopingDbfFile)
                {
                    isLoopingDbfFile = true;
                    dlg = new AsyncDelegate(updateStockBidAskBook);
                    dlg.BeginInvoke(reqId, null, null);
                }
                break;

            case SecurityCategory.OPTION:
                this.htSubscribedOptions.Add(s.code, s.bidaskbook);
                if (!isLoopingMktFile)
                {
                    isLoopingMktFile = true;
                    dlg = new AsyncDelegate(updateOptionBidAskBook);
                    dlg.BeginInvoke(reqId, null, null);
                }
                break;

            default:
                string msg = string.Format("无法读取该类证券行情:{0}", s.category);
                MessageManager.GetInstance().Add(MessageType.Error, msg);
                throw new Exception(msg);
            }
        }
示例#33
0
 private void Freeze()
 {
     AsyncDelegate freezeDelegate = new AsyncDelegate(FreezeAsync);
     BeginInvoke(freezeDelegate);
 }
示例#34
0
    /// <summary>
    /// Initiates the asynchronous execution of the SQL statement or stored procedure 
    /// that is described by this <see cref="MySqlCommand"/> using one of the 
    /// <b>CommandBehavior</b> values. 
    /// </summary>
    /// <param name="behavior">One of the <see cref="CommandBehavior"/> values, indicating 
    /// options for statement execution and data retrieval.</param>
    /// <returns>An <see cref="IAsyncResult"/> that can be used to poll, wait for results, 
    /// or both; this value is also needed when invoking EndExecuteReader, 
    /// which returns a <see cref="MySqlDataReader"/> instance that can be used to retrieve 
    /// the returned rows. </returns>
    public IAsyncResult BeginExecuteReader(CommandBehavior behavior)
    {
      if (caller != null)
        Throw(new MySqlException(Resources.UnableToStartSecondAsyncOp));

      caller = new AsyncDelegate(AsyncExecuteWrapper);
      asyncResult = caller.BeginInvoke(1, behavior, null, null);
      return asyncResult;
    }
示例#35
0
 protected void BeginInvoke(AsyncDelegate del)
 {
     del.BeginInvoke(EndInvoke, del);
 }
示例#36
0
 private void Read()
 {
     AsyncDelegate read = new AsyncDelegate(ReadAsync);
     BeginInvoke(read);
 }
示例#37
0
 private void Begin()
 {
     AsyncDelegate begin = new AsyncDelegate(BeginAsync);
     BeginInvoke(begin);
 }
示例#38
0
 private void Recover()
 {
     AsyncDelegate recover = new AsyncDelegate(RecoverAsync);
     BeginInvoke(recover);
 }
示例#39
0
 private void Fail()
 {
     AsyncDelegate fail = new AsyncDelegate(FailAsync);
     BeginInvoke(fail);
 }
示例#40
0
 private void Connect()
 {
     AsyncDelegate connect = new AsyncDelegate(ConnectAsync);
     BeginInvoke(connect);
 }
示例#41
0
        /// <summary>
        /// Initiates the asynchronous execution of the SQL statement or stored procedure
        /// that is described by this <see cref="MySqlCommand"/>.
        /// </summary>
        /// <param name="callback">
        /// An <see cref="AsyncCallback"/> delegate that is invoked when the command's
        /// execution has completed. Pass a null reference (<b>Nothing</b> in Visual Basic)
        /// to indicate that no callback is required.</param>
        /// <param name="stateObject">A user-defined state object that is passed to the
        /// callback procedure. Retrieve this object from within the callback procedure
        /// using the <see cref="IAsyncResult.AsyncState"/> property.</param>
        /// <returns>An <see cref="IAsyncResult"/> that can be used to poll or wait for results,
        /// or both; this value is also needed when invoking <see cref="EndExecuteNonQuery"/>,
        /// which returns the number of affected rows. </returns>
        public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObject)
        {
            if (caller != null)
                throw new MySqlException("ResourceStrings.UnableToStartSecondAsyncOp");

            caller = new AsyncDelegate(AsyncExecuteWrapper);
            asyncResult = caller.BeginInvoke(2, CommandBehavior.Default,
                callback, stateObject);
            return asyncResult;
        }
示例#42
0
 public static void Write(LogEvent log)
 {
     try
     {
         AsyncDelegate ad = new AsyncDelegate(write);
         ad.BeginInvoke(log, new AsyncCallback(CallbackMethod), ad);
     }
     catch { }
 }
示例#43
0
        public static void OpenAttachmentAsync(Control Ctrl, int AttachmentID, int ConnectionID)
        {
            Ctrl.UseWaitCursor = true;

            // Create the delegate.
            AsyncDelegate dlgt = new AsyncDelegate(Utils.OpenAttachment);

            // Initiate the asychronous call.  Include an AsyncCallback
            // delegate representing the callback method, and the data
            // needed to call EndInvoke.
            IAsyncResult ar = dlgt.BeginInvoke(Ctrl, AttachmentID, ConnectionID, new AsyncCallback(CallbackMethod), dlgt);
        }
示例#44
0
 public void Invoke(AsyncDelegate del)
 {
     Invoke(del, false);
 }
示例#45
0
 public void Invoke(AsyncDelegate del, bool wait)
 {
     ControllerMainAction mainAction = new SimpleDefaultMainAction(this, del);
     invoke(mainAction, wait);
 }
示例#46
0
		/// <summary>
		/// Initiates the asynchronous execution of the SQL statement or stored procedure 
		/// that is described by this <see cref="MySqlCommand"/>. 
		/// </summary>
		/// <param name="callback">
		/// An <see cref="AsyncCallback"/> delegate that is invoked when the command's 
		/// execution has completed. Pass a null reference (<b>Nothing</b> in Visual Basic) 
		/// to indicate that no callback is required.</param>
		/// <param name="stateObject">A user-defined state object that is passed to the 
		/// callback procedure. Retrieve this object from within the callback procedure 
		/// using the <see cref="IAsyncResult.AsyncState"/> property.</param>
		/// <returns>An <see cref="IAsyncResult"/> that can be used to poll or wait for results, 
		/// or both; this value is also needed when invoking <see cref="EndExecuteNonQuery"/>, 
		/// which returns the number of affected rows. </returns>
		public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObject)
		{
			AsyncDelegate del = new AsyncDelegate(AsyncExecuteWrapper);
			asyncResult = del.BeginInvoke(2, CommandBehavior.Default, 
				callback, stateObject);
			return asyncResult;
		}
示例#47
0
 public void Background(AsyncDelegate del, AsyncDelegate cleanup)
 {
     // Move to background thread
     background(new AsyncDelegateBackgroundAction(del, cleanup));
 }
示例#48
0
		/// <summary>
		/// Initiates the asynchronous execution of the SQL statement or stored procedure 
		/// that is described by this <see cref="MySqlCommand"/> using one of the 
		/// <b>CommandBehavior</b> values. 
		/// </summary>
		/// <param name="behavior">One of the <see cref="CommandBehavior"/> values, indicating 
		/// options for statement execution and data retrieval.</param>
		/// <returns>An <see cref="IAsyncResult"/> that can be used to poll, wait for results, 
		/// or both; this value is also needed when invoking EndExecuteReader, 
		/// which returns a <see cref="MySqlDataReader"/> instance that can be used to retrieve 
		/// the returned rows. </returns>
		public IAsyncResult BeginExecuteReader(CommandBehavior behavior)
		{
			AsyncDelegate del = new AsyncDelegate(AsyncExecuteWrapper);
			asyncResult = del.BeginInvoke(1, behavior, null, null);
			return asyncResult;
		}
示例#49
0
    /// <summary>
    /// Initiates the asynchronous execution of the SQL statement or stored procedure 
    /// that is described by this <see cref="MySqlCommand"/>. 
    /// </summary>
    /// <returns>An <see cref="IAsyncResult"/> that can be used to poll or wait for results, 
    /// or both; this value is also needed when invoking <see cref="EndExecuteNonQuery"/>, 
    /// which returns the number of affected rows. </returns>
    public IAsyncResult BeginExecuteNonQuery()
    {
      if (caller != null)
        Throw(new MySqlException(Resources.UnableToStartSecondAsyncOp));

      caller = new AsyncDelegate(AsyncExecuteWrapper);
      asyncResult = caller.BeginInvoke(2, CommandBehavior.Default, null, null);
      return asyncResult;
    }
示例#50
0
 private void Create()
 {
     AsyncDelegate create = new AsyncDelegate(CreateAsync);
     BeginInvoke(create);
 }
示例#51
0
 private void Write()
 {
     AsyncDelegate write = new AsyncDelegate(WriteAsync);
     BeginInvoke(write);
 }
示例#52
0
 private void Commit()
 {
     AsyncDelegate commit = new AsyncDelegate(CommitAsync);
     BeginInvoke(commit);
 }
示例#53
0
		/// <summary>
		/// Initiates the asynchronous execution of the SQL statement or stored procedure 
		/// that is described by this <see cref="MySqlCommand"/>. 
		/// </summary>
		/// <returns>An <see cref="IAsyncResult"/> that can be used to poll or wait for results, 
		/// or both; this value is also needed when invoking <see cref="EndExecuteNonQuery"/>, 
		/// which returns the number of affected rows. </returns>
		public IAsyncResult BeginExecuteNonQuery()
		{
			AsyncDelegate del = new AsyncDelegate(AsyncExecuteWrapper);
			asyncResult = del.BeginInvoke(2, CommandBehavior.Default, null, null);
			return asyncResult;
		}
示例#54
0
 protected void BeginInvoke(AsyncDelegate del)
 {
     // thread the delegate, as a fire and forget.
     del.BeginInvoke(EndAsync, del);
 }
示例#55
0
 private void Access()
 {
     AsyncDelegate access = new AsyncDelegate(AccessAsync);
     BeginInvoke(access);
 }
示例#56
0
 /// <summary>
 /// Finishes asynchronous execution of a SQL statement, returning the requested 
 /// <see cref="MySqlDataReader"/>.
 /// </summary>
 /// <param name="result">The <see cref="IAsyncResult"/> returned by the call to 
 /// <see cref="BeginExecuteReader()"/>.</param>
 /// <returns>A <b>MySqlDataReader</b> object that can be used to retrieve the requested rows. </returns>
 public MySqlDataReader EndExecuteReader(IAsyncResult result)
 {
   result.AsyncWaitHandle.WaitOne();
   AsyncDelegate c = caller;
   caller = null;
   if (thrownException != null)
     throw thrownException;
   return (MySqlDataReader)c.EndInvoke(result);
 }
示例#57
0
 private void Abort()
 {
     AsyncDelegate abort = new AsyncDelegate(AbortAsync);
     BeginInvoke(abort);
 }
示例#58
0
 /// <summary>
 /// Finishes asynchronous execution of a SQL statement. 
 /// </summary>
 /// <param name="asyncResult">The <see cref="IAsyncResult"/> returned by the call 
 /// to <see cref="BeginExecuteNonQuery()"/>.</param>
 /// <returns></returns>
 public int EndExecuteNonQuery(IAsyncResult asyncResult)
 {
   asyncResult.AsyncWaitHandle.WaitOne();
   AsyncDelegate c = caller;
   caller = null;
   if (thrownException != null)
     throw thrownException;
   return (int)c.EndInvoke(asyncResult);
 }
 static void Main(){
   AsyncDelegate asyncDlg = new AsyncDelegate();
   asyncDlg.Run();
 }