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

📄 packlist.cs

📁 这个是基于SMPP的开发源码
💻 CS
字号:
using System;
using System.Collections;
using System.Text;
using System.Threading;

namespace SMGP3_0
{
	class PackList : CollectionBase
	{
		public delegate void PackTimeOutEventHandler(PackList Sender, SMGPPack Pack);
		public event PackTimeOutEventHandler OnPackTimeOut;

		private int _TimeOut = 60;
		public int TimeOut
		{
			get
			{
				return _TimeOut;
			}
			set
			{
				_TimeOut = value;
			}
		}

		private Thread MyThread;
		private bool RUN = false;

		public PackList()
		{
		}
		
		public PackList(int TimeOut)
		{
			_TimeOut = TimeOut;
		}

		private object Lock = new object();

		public void Start()
		{
			while (MyThread == null || !MyThread.IsAlive)
			{
				RUN = true;
				MyThread = new Thread(new ThreadStart(DetectTimeOut));
				MyThread.Start();
			}
		}

		public void Stop()
		{
			RUN = false;
		}

		private void DetectTimeOut()
		{
			while (RUN)
			{
				SMGPPack Pack = null;
				lock (Lock)
				{
					foreach (SMGPPack pack in List)
					{
						if ((DateTime.Now - pack.SendTime).TotalSeconds > _TimeOut)
						{
							Pack = pack;
							break;
						}
					}
				}

				if (Pack != null)
				{
					Remove(Pack);
					if (OnPackTimeOut != null)
						OnPackTimeOut.BeginInvoke(this, Pack, null, null);
				}
				else
					Thread.Sleep(3000);
			}
		}

		public int Add(SMGPPack Pack)
		{
			int Index = 0;
			Pack.SendTime = DateTime.Now;

			lock (Lock)
			{
				Index = List.Add(Pack);
			}

			return Index;
		}

		public int Remove(SMGPPack Pack)
		{
			int Index;
			
			lock (Lock)
			{
				Index = List.IndexOf(Pack);

				if (Index != -1)
					List.Remove(Pack);
			}
			return Index;
		}

		public SMGPPack Remove(int Index)
		{
			SMGPPack Pack;

			lock (Lock)
			{
				Pack = (SMGPPack)(List.Count > Index && Index >= 0 ? List[Index] : null);

				List.RemoveAt(Index);
			}

			return Pack;
		}

		public SMGPPack GetPackBySequenceID(int SequenceID)
		{
			SMGPPack Pack = null;
			lock (Lock)
			{
				foreach (SMGPPack pack in this)
				{
					if (pack.Header.SequenceID == SequenceID)
					{
						Pack = pack;
						break;
					}
				}
			}
			return Pack;
		}
	}
}

⌨️ 快捷键说明

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