public void Add(long entityId)
		{
			TimedEntityCleanupItem item = new TimedEntityCleanupItem();
			item.addedTime = DateTime.Now;
			item.secondsAfterAdding = 5;
			item.entityId = entityId;

			lock (m_items)
				m_items.Add(item);
		}
Ejemplo n.º 2
0
        public void Add(long entityId)
        {
            TimedEntityCleanupItem item = new TimedEntityCleanupItem();

            item.addedTime          = DateTime.Now;
            item.secondsAfterAdding = 5;
            item.entityId           = entityId;

            lock (m_items)
                m_items.Add(item);
        }
Ejemplo n.º 3
0
        public void Process()
        {
            lock (m_items)
            {
                if (!m_items.Any())
                {
                    return;
                }

                for (int r = m_items.Count() - 1; r >= 0; r--)
                {
                    TimedEntityCleanupItem item = m_items[r];

                    if (DateTime.Now - item.addedTime > TimeSpan.FromSeconds(item.secondsAfterAdding))
                    {
                        try
                        {
                            IMyEntity entity = null;
                            Wrapper.GameAction(() =>
                            {
                                MyAPIGateway.Entities.TryGetEntityById(item.entityId, out entity);
                            });

                            if (entity != null)
                            {
                                MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                                if (gridBuilder == null)
                                {
                                    continue;
                                }

                                CubeGridEntity entityToDispose = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
                                entityToDispose.Dispose();
                            }
                            else
                            {
                                Logging.WriteLineAndConsole("Entity is null");
                            }
                        }
                        catch (Exception ex)
                        {
                            Logging.WriteLineAndConsole(string.Format("Dispose Error: {0}", ex.ToString()));
                        }

                        m_items.RemoveAt(r);
                    }
                }
            }
        }
        public void Process()
        {
            lock (m_items)
            {
                if (!m_items.Any())
                {
                    return;
                }

                for (int r = m_items.Count() - 1; r >= 0; r--)
                {
                    TimedEntityCleanupItem item = m_items[r];

                    if (DateTime.Now - item.addedTime > TimeSpan.FromSeconds(item.secondsAfterAdding))
                    {
                        try
                        {
                            IMyEntity entity = null;
                            Wrapper.GameAction(() =>
                            {
                                MyAPIGateway.Entities.TryGetEntityById(item.entityId, out entity);
                            });

                            if (entity != null)
                            {
                                Wrapper.GameAction(() => entity.Close(  ));
                            }
                            else
                            {
                                Log.Info("Entity is null");
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Info(string.Format("Dispose Error: {0}", ex.ToString()));
                        }

                        m_items.RemoveAt(r);
                    }
                }
            }
        }