コード例 #1
0
        void Dispose(bool disposing)
        {
            if (Lock != null)
            {
                if (disposing)
                {
                    ClearAllLevels();
                }

                Levels.Clear();
                Levels = null;

                tmp.Clear();
                tmp = null;

                Lock.Dispose();
                Lock = null;
            }
        }
コード例 #2
0
ファイル: Core.cs プロジェクト: ralex1975/zq
        void Dispose(bool disposing)
        {
            if (IsStarted)
            {
                if (invalidator != null)
                {
                    invalidator.CancelAsync();
                    invalidator.DoWork -= new DoWorkEventHandler(invalidatorWatch);
                    invalidator.Dispose();
                    invalidator = null;
                }

                if (Refresh != null)
                {
                    Refresh.Set();
                    Refresh.Close();
                    Refresh = null;
                }

                int x = Interlocked.Decrement(ref instances);
                Debug.WriteLine("OnMapClose: " + x);

                CancelAsyncTasks();
                IsStarted = false;

                if (Matrix != null)
                {
                    Matrix.Dispose();
                    Matrix = null;
                }

                if (FailedLoads != null)
                {
                    lock (FailedLoads)
                    {
                        FailedLoads.Clear();
                        RaiseEmptyTileError = false;
                    }
                    FailedLoads = null;
                }

                // cancel waiting loaders
                Monitor.Enter(tileLoadQueue);
                try
                {
                    Monitor.PulseAll(tileLoadQueue);
                    tileDrawingList.Clear();
                }
                finally
                {
                    Monitor.Exit(tileLoadQueue);
                }

                lock (GThreadPool)
                {
#if PocketPC
                    Debug.WriteLine("waiting until loaders are stopped...");
                    while (GThreadPool.Count > 0)
                    {
                        var t = GThreadPool[0];

                        if (t.State != ThreadState.Stopped)
                        {
                            var tr = t.Join(1111);

                            Debug.WriteLine(t.Name + ", " + t.State);

                            if (!tr)
                            {
                                continue;
                            }
                            else
                            {
                                GThreadPool.Remove(t);
                            }
                        }
                        else
                        {
                            GThreadPool.Remove(t);
                        }
                    }
                    Thread.Sleep(1111);
#endif
                }

                if (tileDrawingListLock != null)
                {
                    tileDrawingListLock.Dispose();
                    tileDrawingListLock = null;
                    tileDrawingList     = null;
                }

                if (x == 0)
                {
#if DEBUG
                    CFMaps.Instance.CancelTileCaching();
#endif
                    CFMaps.Instance.noMapInstances = true;
                    CFMaps.Instance.WaitForCache.Set();
                    if (disposing)
                    {
                        CFMaps.Instance.MemoryCache.Clear();
                    }
                }
            }
        }