示例#1
0
 private void Init()
 {
     _env = new Environment {
         Height = 10, Width = 10, OffsetXY = new Point(0, 0)
     };
     drawAgent = null;
     drawAgent = new AgentFormOutput(pictureBox1, new Size(_env.Width, _env.Height));
     //firstAgent = new Agent("First Agent", Color.Red, new Point(2, 1), 50,
     //    new Purpose(50, 50, new Point(6, 6)), 50, Temper.Сангвінік) {Engine = new RealEngine()};
     //secondAgent = new Agent("Second Agent", Color.Green, new Point(8, 6), 50,
     //    new Purpose(50, 50, new Point(4, 1)), 50, Temper.Флегматик) {Engine = new RealEngine()};
     if (_agent == null)
     {
         _agent = new List <ThreadAgent>();
     }
     //_agent.Clear();
     clearAllObject += drawAgent.StopAgentFromOutputAndClearAll;
     clearAllObject += _env.StopEnvironmentAndClearAll;
 }
示例#2
0
 private void Clear()
 {
     clearAllObject?.Invoke();
     clearAllObject -= drawAgent.StopAgentFromOutputAndClearAll;
     clearAllObject -= _env.StopEnvironmentAndClearAll;
     drawAgent       = null;
     _env            = null;
     //firstAgent = null;
     //secondAgent = null;
     for (int i = 0; i < _agent.Count; i++)
     {
         clearAllObject -= _agent[i].Agent.StopAgentAndClearAll;
         _agent[i].Agent.Engine.EndWorkEvent -= EndAgentWork;
         _agent[i].Agent = _agent[i].Agent.Clone();
         //_agent[i].Agent = null;
         _agent[i].Thread?.Abort();
         _agent[i].Thread = null;
         //_agent[i] = null;
     }
     //_agent.Clear();
     //_agent = null;
     GC.Collect();
 }