I faced the following problem. I am using separate thread to update the physical world, running this method in separate thread :
Code: Select all
public void Run() {
            try {
            Stopwatch Timer = new Stopwatch();
            Timer.Start();
            IsRunning = true;
            while (IsRunning)
            {
                Log.DebugFormat("Updating physics thread");
                    if (Timer.Elapsed < TimeSpan.FromSeconds(1/30f)) {
                        if (ThreadRegionServer.NumPlayers <= 0) {
                            Thread.Sleep(1000);
                            Timer.Restart();
                        }
                        
                        if ((int) (1000.0f/30.0f - Timer.Elapsed.Milliseconds) > 0) {
                            Thread.Sleep((int)(1000.0f / 30.0f - Timer.Elapsed.Milliseconds));
                        }
                        continue;
                    }
                    
                    Update(Timer.Elapsed);
                    Timer.Restart();
                }
                               
            }
            catch (Exception e)
            {
                Log.DebugFormat("Exception in physics thread : {0}", e.ToString());
            }            
        }
Code: Select all
private void Update(TimeSpan Elapsed) {
            try {
                Log.DebugFormat("BEFORE Updating physics");
                Space.Update();
                Log.DebugFormat("AFTER Updating physics");               
            }
            catch (Exception ex) {
                Log.DebugFormat("Physics update exception {0}", ex.ToString());
            }
        }
Thanks.