diff options
author | Justin Clark-Casey (justincc) | 2011-11-01 18:36:29 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-11-01 18:36:29 +0000 |
commit | 87ec8a4ecbafca79841117ba03cced0aa9f82193 (patch) | |
tree | 5f20e1b66f8029a648730c1e8ebfaa381c149958 /OpenSim/Tools/pCampBot/PhysicsBot.cs | |
parent | Make bots share a cache so that asset downloads attempts are only made once i... (diff) | |
download | opensim-SC_OLD-87ec8a4ecbafca79841117ba03cced0aa9f82193.zip opensim-SC_OLD-87ec8a4ecbafca79841117ba03cced0aa9f82193.tar.gz opensim-SC_OLD-87ec8a4ecbafca79841117ba03cced0aa9f82193.tar.bz2 opensim-SC_OLD-87ec8a4ecbafca79841117ba03cced0aa9f82193.tar.xz |
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
Diffstat (limited to 'OpenSim/Tools/pCampBot/PhysicsBot.cs')
-rw-r--r-- | OpenSim/Tools/pCampBot/PhysicsBot.cs | 28 |
1 files changed, 20 insertions, 8 deletions
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 | |||
62 | public event AnEvent OnConnected; | 62 | public event AnEvent OnConnected; |
63 | public event AnEvent OnDisconnected; | 63 | public event AnEvent OnDisconnected; |
64 | 64 | ||
65 | protected Timer m_action; // Action Timer | 65 | /// <summary> |
66 | /// Keep a track of the continuously acting thread so that we can abort it. | ||
67 | /// </summary> | ||
68 | private Thread m_actionThread; | ||
69 | |||
66 | protected List<uint> objectIDs = new List<uint>(); | 70 | protected List<uint> objectIDs = new List<uint>(); |
67 | 71 | ||
68 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here | 72 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here |
@@ -98,8 +102,7 @@ namespace pCampBot | |||
98 | 102 | ||
99 | //We do our actions here. This is where one would | 103 | //We do our actions here. This is where one would |
100 | //add additional steps and/or things the bot should do | 104 | //add additional steps and/or things the bot should do |
101 | 105 | private void Action() | |
102 | void m_action_Elapsed(object sender, ElapsedEventArgs e) | ||
103 | { | 106 | { |
104 | while (true) | 107 | while (true) |
105 | { | 108 | { |
@@ -145,6 +148,9 @@ namespace pCampBot | |||
145 | /// </summary> | 148 | /// </summary> |
146 | public void shutdown() | 149 | public void shutdown() |
147 | { | 150 | { |
151 | if (m_actionThread != null) | ||
152 | m_actionThread.Abort(); | ||
153 | |||
148 | client.Network.Logout(); | 154 | client.Network.Logout(); |
149 | } | 155 | } |
150 | 156 | ||
@@ -177,11 +183,10 @@ namespace pCampBot | |||
177 | { | 183 | { |
178 | if (OnConnected != null) | 184 | if (OnConnected != null) |
179 | { | 185 | { |
180 | m_action = new Timer(somthing.Next(1000, 10000)); | 186 | Thread.Sleep(somthing.Next(1000, 10000)); |
181 | m_action.Enabled = true; | 187 | m_actionThread = new Thread(Action); |
182 | m_action.AutoReset = false; | 188 | m_actionThread.Start(); |
183 | m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); | 189 | |
184 | m_action.Start(); | ||
185 | // OnConnected(this, EventType.CONNECTED); | 190 | // OnConnected(this, EventType.CONNECTED); |
186 | if (wear == "save") | 191 | if (wear == "save") |
187 | { | 192 | { |
@@ -386,6 +391,13 @@ namespace pCampBot | |||
386 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) | 391 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) |
387 | { | 392 | { |
388 | // m_log.ErrorFormat("Fired Network_OnDisconnected"); | 393 | // m_log.ErrorFormat("Fired Network_OnDisconnected"); |
394 | |||
395 | // Only pass on the disconnect message when we receive a SimShutdown type shutdown. We have to ignore | ||
396 | // the earlier ClientInitiated shutdown callback. | ||
397 | // if ( | ||
398 | // (args.Reason == NetworkManager.DisconnectType.SimShutdown | ||
399 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) | ||
400 | // && OnDisconnected != null) | ||
389 | if (OnDisconnected != null) | 401 | if (OnDisconnected != null) |
390 | { | 402 | { |
391 | OnDisconnected(this, EventType.DISCONNECTED); | 403 | OnDisconnected(this, EventType.DISCONNECTED); |