• C#异步


    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);
            }
        }
    }
  • 相关阅读:
    0xc000000f: Error attempting to read the boot configuration data
    结合使用 Oracle Database 11g 和 Python
    精通 Oracle+Python,第 9 部分:Jython 和 IronPython — 在 Python 中使用 JDBC 和 ODP.NET
    精通 Oracle+Python,第 8 部分:适合 Oracle DBA 使用的 Python
    精通 Oracle+Python,第 6 部分:Python 支持 XML
    精通 Oracle+Python,第 7 部分:面向服务的 Python 架构
    精通 Oracle+Python,第 5 部分:存储过程、Python 编程
    精通 Oracle+Python,第 4 部分:事务和大型对象
    精通 Oracle+Python,第 3 部分:数据解析
    精通 Oracle+Python,第 2 部分:处理时间和日期
  • 原文地址:https://www.cnblogs.com/daixingqing/p/4429346.html
Copyright © 2020-2023  润新知