agentdomainproxy.cs

来自「Agent技术在智能交通中的应用」· CS 代码 · 共 39 行

CS
39
字号
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading;


namespace MobileAgents
{
	/// <summary>
	/// The AgentDomainProxy class is essentially the interface between
	/// an agent application domain and the host application domain.  It is 
	/// through this class that the host injects agents into this app domain.
	/// </summary>
	internal class AgentDomainProxy : MarshalByRefObject
	{
		/// <summary>
		/// Hosts the agent given by queueing it with the thread pool
		/// </summary>
		/// <param name="a">The agent to host.</param>
		public void HostAgent(Agent a) 
		{
			//Use the CLR thread pool to launch this guy!
			ThreadPool.QueueUserWorkItem(new WaitCallback(RunAgent), a);
		}

		/// <summary>
		/// The WaitCallback delegate method for the ThreadPool.
		/// This method actually runs the agent.
		/// </summary>
		/// <param name="context"></param>
		private void RunAgent(object context)
		{
			Agent a = context as Agent;
			a.Run();
		}
	}
}

⌨️ 快捷键说明

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