C#非同步

來源:互聯網
上載者:User

標籤:

using System;using System.Threading;using System.Runtime.Remoting.Messaging;using System.Collections.Generic;namespace PurchaseSystem.Component{    public enum FlowType    {        CaiGou,        YingFu    }    public delegate void ProccessFlowDelegate(FlowType type);    public class Flow    {        private void AsyncFlow(FlowType type, Action<IAsyncResult, bool> callback = null)        {            ProccessFlowDelegate asyncFlow = AsyncFlowHandler;            IAsyncResult asyncResult = asyncFlow.BeginInvoke(type, AsyncFlowCallback, null);            ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle,                AsyncFlowCompleteCallback, new List<object>() { asyncResult, callback },                1800000, true);        }        private static void AsyncFlowCompleteCallback(object state, bool isTimeout)        {            List<object> stateList = state as List<object>;            IAsyncResult result = stateList[0] as IAsyncResult;            Action<IAsyncResult, bool> callback = stateList[1] as Action<IAsyncResult, bool>;            if (isTimeout)            {                if (!result.IsCompleted)                {                    result.AsyncWaitHandle.Close();                }            }            callback(result, isTimeout);        }        private static void AsyncFlowCallback(IAsyncResult result)        {            ProccessFlowDelegate d = (ProccessFlowDelegate)((AsyncResult)result).AsyncDelegate;            d.EndInvoke(result);        }        private void AsyncFlowHandler(FlowType type)        {            if (type == FlowType.CaiGou)            {            }            else if (type == FlowType.YingFu)            {            }        }        public void CaiGouProccess(Guid purchaseApplyId)        {            AsyncFlow(FlowType.CaiGou, null);        }    }}
using System;using System.Threading;using System.Collections.Generic;using System.Runtime.Remoting.Messaging;namespace PurchaseSystem.Component{    public enum FlowProcessType     {        CaiGou,        YingFu    }    public delegate void FlowProcessDelegate(FlowProcessType type, params object[] parameters);    public class FlowProcess    {        private void AsyncFlowProcess(FlowProcessType type, params object[] parameters)        {            FlowProcessDelegate asyncMailNotice = AsyncFlowProcessHandler;            IAsyncResult asyncResult = asyncMailNotice.BeginInvoke(type, parameters, FlowProcessCallback, null);            ThreadPool.RegisterWaitForSingleObject(              asyncResult.AsyncWaitHandle,              FlowProcessCompleteCallback,              new List<object>() { asyncResult },              1800000,              true);        }        private void FlowProcessCallback(IAsyncResult result)        {            MailNoticeDelegate d = (MailNoticeDelegate)((AsyncResult)result).AsyncDelegate;            d.EndInvoke(result);        }        private void FlowProcessCompleteCallback(object state, bool isTimeout)        {            List<object> stateList = state as List<object>;            IAsyncResult result = stateList[0] as IAsyncResult;            if (isTimeout)            {                if (!result.IsCompleted)                {                    result.AsyncWaitHandle.Close();                }            }        }        private void AsyncFlowProcessHandler(FlowProcessType type, params object[] parameters)        {            if (type == FlowProcessType.CaiGou)            {            }        }        public void PurchaseApplyApprovalMailNotice2(Guid purchaseApplyId)        {            AsyncFlowProcess(FlowProcessType.CaiGou, purchaseApplyId);        }    }}

 

C#非同步

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.