⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recprocthread.cs

📁 监控系统
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using MonitorSystem.LogFileModule;
using MonitorSystem.BasicClass;

namespace MonitorSystem.MonitorCenter
{
	/// <summary>
	/// RecordProcessThread 的摘要说明。
	/// </summary>
	public class RecProcThread
	{
		private Thread m_Thread;
		private bool m_Pause;
		private bool m_Exit;

		private RecordQueue m_queRecord;
		private ConfigFile m_CfgFile;
		private SystemLog m_SysLog;
		private DateTime CreateTime;

		public void Init(ref RecordQueue iRecordQueue, ref ConfigFile iConfigFile)
		{
			this.m_queRecord = iRecordQueue;
			this.m_CfgFile = iConfigFile;
			this.m_SysLog = new SystemLog();
			CreateTime = new DateTime(2004,1,1,0,0,0);
		}

		public void Run()
		{
			string sqlConn = m_CfgFile.ConnectionStr;

			while(true)
			{
				while(m_Pause)
				{
					try
					{
						Thread.Sleep(1000);
					}
					catch(Exception)
					{						
					}
					continue;
				}
				if(m_Exit)
				{
					break;
				}

				if (m_queRecord.Count <= 0)
				{
					try
					{
						Thread.Sleep(1000);
						continue;
					}
					catch(Exception)
					{
						continue;
					}
				}

				LogFile log = new LogFile();
				log = (LogFile)m_queRecord.Dequeue();

				try
				{
					int nRet=log.WriteToDB(sqlConn,m_CfgFile.LogTableName,m_CfgFile.AlertTableName);
					if(nRet!=0)
					{
						m_SysLog.WriteToSysLog("该记录插入监控日志表失败");
					}
				}
				catch(Exception error1)
				{
					m_SysLog.WriteToSysLog("该记录插入监控日志表失败,原因:{0}",error1.Message);
				}

				try
				{
					Thread.Sleep(100);
				}
				catch(Exception)
				{						
				}
								
			}			
		}

		public void Startup()
		{ 				
			m_Thread = new Thread(new ThreadStart(this.Run));
			// Start the thread
			m_Pause = false;
			m_Exit = false;		
			m_Thread.Start();			
		}
		public void Join()
		{
			if(m_Thread != null)
			{
				m_Thread.Interrupt();
				m_Thread.Join();
			}
			else
			{
				return;
			}
		}
		public bool IsAlive()
		{
			if(m_Thread != null)
			{
				return m_Thread.IsAlive;
			}
			else
			{
				return false;
			}
		}
		public void Suspend()
		{
			if(m_Pause == false)
				m_Pause = true;
		}
		public void Resume()
		{
			if(m_Pause == true)
				m_Pause = false;		
		}
		public void SetExit()
		{
			if(m_Exit == false)
				m_Exit = true;		
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -