Пример #1
0
        /// <summary>
        /// 是否有线程需要启动执行
        /// </summary>
        /// <returns></returns>
        internal bool IsHaveProgressStart()
        {
            if (this.m_ThrdList == null)
            {
                this.m_ThrdList = new ArrayList();
            }
            bool         bResut       = false;
            SearchThread searchThread = null;

            for (int nIndex = 0; nIndex < this.m_ThrdList.Count; nIndex++)
            {
                searchThread = this.m_ThrdList[nIndex] as SearchThread;
                if (searchThread == null)
                {
                    continue;
                }
                if (searchThread.ThreadState == EMRDBLib.SearchThreadState.running ||
                    searchThread.ThreadState == EMRDBLib.SearchThreadState.ready)
                {
                    bResut = true;
                    break;
                }
            }
            return(bResut);
        }
Пример #2
0
        /// <summary>
        /// 根据线程名称获取线程对象
        /// </summary>
        /// <param name="szTreadName">线程名称</param>
        /// <returns>线程对象</returns>
        internal SearchThread Item(string szTreadName)
        {
            if (this.m_ThrdList == null)
            {
                return(null);
            }
            SearchThread searchThread = null;
            SearchThread temp         = new SearchThread();
            int          i            = 0;

            while (i < this.m_ThrdList.Count)
            {
                temp = (SearchThread)this.m_ThrdList[i];
                if (temp == null)
                {
                    continue;
                }
                if (temp.Name == szTreadName)
                {
                    searchThread = temp;
                }
                System.Math.Min(Interlocked.Increment(ref i), i - 1);
            }
            return(searchThread);
        }
Пример #3
0
        /// <summary>
        /// 将线程添加到线程池中
        /// </summary>
        /// <param name="szDeptCode">科室代码</param>
        /// <param name="dtBeginTime">查询起始时间</param>
        /// <param name="dtEndTime">查询截止时间</param>
        /// <param name="patientType">检索方式</param>
        /// <param name="patientListForm">患者列表检索窗口</param>
        /// <param name="patSearchType">患者质控方式</param>
        private void AddSearchThread(string szDeptCode, DateTime dtBeginTime, DateTime dtEndTime, EMRDBLib.PatientType patientType
                                     , PatientListForm patientListForm, EMRDBLib.PatSearchType patSearchType, string szOperationCode, MDSDBLib.DocTypeInfo docTypeInfo)
        {
            if (this.m_ThrdList == null)
            {
                this.m_ThrdList = new ArrayList();
            }
            string szThreadName = "Thread" + (this.m_ThrdList.Count + 1).ToString();

            dtEndTime = DateTime.Parse(dtEndTime.ToString("yyyy-M-d 23:59:59"));
            PatSearchCondition searchConditon = new PatSearchCondition(szThreadName, szDeptCode, patientListForm, dtBeginTime, dtEndTime
                                                                       , patientType, patSearchType, szOperationCode, docTypeInfo);
            SearchThread searchThread = new SearchThread();

            searchThread.Name               = szThreadName;
            searchThread.Thread             = null;
            searchThread.ThreadState        = EMRDBLib.SearchThreadState.ready;
            searchThread.PatSearchCondition = searchConditon;
            this.m_ThrdList.Add(searchThread);
        }
Пример #4
0
        /// <summary>
        ///启动检索线程(启动下一个未启动的线程)
        /// </summary>
        internal bool StartNextThread()
        {
            if (this.m_ThrdList == null)
            {
                return(false);
            }

            bool         bResult     = false;
            SearchThread startThread = new SearchThread();

            for (int nIndex = 0; nIndex < this.m_ThrdList.Count; nIndex++)
            {
                startThread = this.m_ThrdList[nIndex] as SearchThread;
                if (startThread == null)
                {
                    continue;
                }
                if (startThread.ThreadState != EMRDBLib.SearchThreadState.ready)
                {
                    continue;
                }

                bResult = true;
                Thread thread = null;
                try
                {
                    thread             = new Thread(new ThreadStart(startThread.PatSearchCondition.SearchPatInfos));
                    thread.Name        = startThread.Name;
                    startThread.Thread = thread;
                    thread.Start();
                    return(bResult);
                }
                catch (Exception ex)
                {
                    LogManager.Instance.WriteLog("检索数据时出错!", ex, LogType.Warning);
                    bResult = false;
                    break;
                }
            }
            return(bResult);
        }
Пример #5
0
        /// <summary>
        /// 所有线程是否已经完成执行
        /// </summary>
        /// <returns></returns>
        internal bool IsFinishProgress()
        {
            if (this.m_ThrdList == null)
            {
                return(true);
            }
            SearchThread st     = default(SearchThread);
            int          nIndex = 0;

            for (nIndex = 0; nIndex < this.m_ThrdList.Count; nIndex += 1)
            {
                st = this.m_ThrdList[nIndex] as SearchThread;
                if (st == null)
                {
                    continue;
                }
                if (st.ThreadState != EMRDBLib.SearchThreadState.finished)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #6
0
        /// <summary>
        /// 终止线程检索数据
        /// </summary>
        public short StopThreadsWork()
        {
            if (this.m_ThrdList == null || this.m_ThrdList.Count <= 0)
            {
                return(SystemData.ReturnValue.OK);
            }

            if (this.IsHaveProgressStart())
            {
                int nCount = this.m_ThrdList.Count;
                for (int nIndex = 0; nIndex < nCount; nIndex++)
                {
                    SearchThread searchThread = (SearchThread)this.m_ThrdList[nIndex];
                    if (searchThread.ThreadState != EMRDBLib.SearchThreadState.running)
                    {
                        searchThread.ThreadState = EMRDBLib.SearchThreadState.cancelled;
                        continue;
                    }
                    Thread thread = null;
                    try
                    {
                        thread = searchThread.Thread;
                        if ((thread != null))
                        {
                            thread.Abort();
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Instance.WriteLog("线程执行出现异常", ex, LogType.Error);
                        return(SystemData.ReturnValue.FAILED);
                    }
                }
            }
            return(SystemData.ReturnValue.OK);
        }