From 87ec8a4ecbafca79841117ba03cced0aa9f82193 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 1 Nov 2011 18:36:29 +0000
Subject: Retain a reference to an action thread rather than starting an
infinite loop via a timer, so that we can actually abort the action thread on
shutdown
---
OpenSim/Tools/pCampBot/PhysicsBot.cs | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
(limited to 'OpenSim/Tools/pCampBot/PhysicsBot.cs')
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
index 2070bfd..945697b 100644
--- a/OpenSim/Tools/pCampBot/PhysicsBot.cs
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -62,7 +62,11 @@ namespace pCampBot
public event AnEvent OnConnected;
public event AnEvent OnDisconnected;
- protected Timer m_action; // Action Timer
+ ///
+ /// Keep a track of the continuously acting thread so that we can abort it.
+ ///
+ private Thread m_actionThread;
+
protected List objectIDs = new List();
protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here
@@ -98,8 +102,7 @@ namespace pCampBot
//We do our actions here. This is where one would
//add additional steps and/or things the bot should do
-
- void m_action_Elapsed(object sender, ElapsedEventArgs e)
+ private void Action()
{
while (true)
{
@@ -145,6 +148,9 @@ namespace pCampBot
///
public void shutdown()
{
+ if (m_actionThread != null)
+ m_actionThread.Abort();
+
client.Network.Logout();
}
@@ -177,11 +183,10 @@ namespace pCampBot
{
if (OnConnected != null)
{
- m_action = new Timer(somthing.Next(1000, 10000));
- m_action.Enabled = true;
- m_action.AutoReset = false;
- m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed);
- m_action.Start();
+ Thread.Sleep(somthing.Next(1000, 10000));
+ m_actionThread = new Thread(Action);
+ m_actionThread.Start();
+
// OnConnected(this, EventType.CONNECTED);
if (wear == "save")
{
@@ -386,6 +391,13 @@ namespace pCampBot
public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
{
// m_log.ErrorFormat("Fired Network_OnDisconnected");
+
+ // Only pass on the disconnect message when we receive a SimShutdown type shutdown. We have to ignore
+ // the earlier ClientInitiated shutdown callback.
+// if (
+// (args.Reason == NetworkManager.DisconnectType.SimShutdown
+// || args.Reason == NetworkManager.DisconnectType.NetworkTimeout)
+// && OnDisconnected != null)
if (OnDisconnected != null)
{
OnDisconnected(this, EventType.DISCONNECTED);
--
cgit v1.1