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

📄 packettracker.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
字号:
using System;
using System.Windows.Forms;
using System.Collections;
using gowk.core;
using gowk.core.packets;
namespace gowk.core.managers
{
	/// <summary>
	/// it's not a good idea to use a timer to tacker the packets
	/// it seams 
	/// </summary>
	public class PacketTracker
	{
		System.Timers.Timer timer;
		private ArrayList alTackers;
		private Control control;
		private static PacketTracker instance=new PacketTracker();
		public JabberClient jc;
		public JabberClient JabberClient
		{
			get{return this.jc;}
			set{this.jc=value;}
		}
		public PacketTracker()
		{
			this.alTackers=new ArrayList();
			timer=new System.Timers.Timer();
			timer.Interval=50;
			timer.Elapsed+=new System.Timers.ElapsedEventHandler(timer_Elapsed);
		}
		public static PacketTracker Instance
		{
			get{return instance;}
		}
		public virtual void Track(Packet p,JabberCallBack dlgt,int timeout)
		{
			if(timeout<=0 ||dlgt==null)return;
			this.timer.Enabled=true;
			this.alTackers.Add(new TackerOjbect(p,dlgt,timeout));
		}
		protected internal virtual void Invoke(JabberCallBack dlgt,JabberEventArgs e)
		{
			if((this.control!=null) &&this.jc.Control.InvokeRequired)
			{
				this.control.BeginInvoke(dlgt,new object[]{e});
			}
			else
			{
				dlgt.BeginInvoke(e,null,null);
			}
		}

		private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
		{
			for(int i=0;i<this.alTackers.Count;i++)
			{
				TackerOjbect to=(TackerOjbect)this.alTackers[i];
				to.TimeLeft-=(int)this.timer.Interval;
				if(to.TimeLeft<=0)
				{
					this.alTackers.Remove(to);
					this.Invoke(to.CallBack,new JabberEventArgs(to.Packet,null));
				}
			}
			if(this.alTackers.Count==0)
			{
				this.timer.Enabled=false;
			}
		}
		protected internal void OnMessage(Packet p)
		{
			for(int i=0;i<this.alTackers.Count;i++)
			{
				TackerOjbect to=(TackerOjbect)this.alTackers[i];
				if(to.Packet.ID==p.ID)
				{
					this.alTackers.Remove(to);
					this.Invoke(to.CallBack,new JabberEventArgs(to.Packet,p));
				}
			}
		}
		private class TackerOjbect
		{
			public TackerOjbect(Packet p,JabberCallBack callback,int timeout)
			{
				this.Packet=p;this.TimeLeft=timeout;this.CallBack=callback;
			}
			public Packet Packet;
			public int TimeLeft=0;
			public JabberCallBack CallBack;
		}
	}
}

⌨️ 快捷键说明

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