Exemple #1
0
        internal void TerminateWF(Session session)
        {
            //MethodBase methodInfo = MethodBase.GetCurrentMethod();
            if (this.BeginTerminateWF != null)
                this.BeginTerminateWF(MethodTerminateWF, new object[] { session });

            try
            { 
                //Vincent 2014-11-17 second step release remaing wf & host thread after one million second
                Thread.Sleep(50);
                bool hasCloseThread = false;
                if (session.GetHostWaitingCount > 0 ||
                   session.GetWFWaitingCount > 0 &&
                   this.TerminateWFWarnLog != null)
                {
                    this.TerminateWFWarnLog(MethodTerminateWF, string.Format(MsgTerminateWFBegin, session.GetHostWaitingCount.ToString(), session.GetWFWaitingCount));
                    hasCloseThread = true;
                }

                session.WFThreadClose();
                session.HostThreadClose();
                if (hasCloseThread)
                {
                    this.TerminateWFWarnLog(MethodTerminateWF, string.Format(MsgTerminateWFEnd, session.GetHostWaitingCount.ToString(), session.GetWFWaitingCount));
                }

                if (session.WorkflowInstance != null)
                {
                    string gKey = Session.GetGlobalSessionKey(session);
                    try
                    {
                        session.WorkflowInstance.Terminate("Session:" + gKey + " cleared.");
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                //'if the workflow has completed or terminated, WorkflowInstance.Terminate() would cause an exception, 
                //'this exception should not be thrown up the call stack.
                if (this.ErrorInTerminateWF != null)
                    this.ErrorInTerminateWF(MethodTerminateWF, new object[] { session }, ex);
            }
            finally
            {
                if (this.EndTerminateWF != null)
                    this.EndTerminateWF(MethodTerminateWF, new object[] { session });
            }
        }