-1

I have to check database for some scheduled task when it is his time do something.

But when it has run (without calling any other function), it occupies my hard drive every 5 min, 70MB. Is this normal? How can I solve this problem?

static void Main(string[] args)
{
    //dhpGroup_kukuEntities _efEntities = new dhpGroup_kukuEntities();
    while (true)
    {
            DateTime ServerNOW= DateTime.Now;

            using (dhpGroup_kukuEntities _efEntities = new dhpGroup_kukuEntities())
            {
                List<Schedual_JSON> ListSchedual = new List<Schedual_JSON>();
                var a =
                    _efEntities.Schedual_JSON.Where(
                        x =>
                            x.SCHJS_DateTimeSchedual.Value.Year == ServerNOW.Year &&
                            x.SCHJS_DateTimeSchedual.Value.Month == ServerNOW.Month &&
                            x.SCHJS_DateTimeSchedual.Value.Day == ServerNOW.Day &&
                            x.SCHJS_DateTimeSchedual.Value.Hour == ServerNOW.Hour &&
                            x.SCHJS_DateTimeSchedual.Value.Minute == ServerNOW.Minute &&
                            x.SCHHS_SendToThread == false).ToList();

                if (a.Count > 0)
                {
                    for (int i = 0; i < a.Count; i++)
                    {
                        Console.WriteLine("One Task Found!");
                    }

                    ThreadPool.QueueUserWorkItem(o => GetSchedualList(a));

                    foreach (var VARIABLE in a)
                    {
                        Console.WriteLine("One Scudule Regarding to User({0}) With {1} Channel(s) and {2} files Run to BasicThread", _efEntities.AspNetUsers.FirstOrDefault(x => x.Id == VARIABLE.SCHJS_UserID).UserName, getChannelCount(VARIABLE), getFileCount(VARIABLE));
                        VARIABLE.SCHHS_SendToThread = true;
                    }

                    _efEntities.SaveChanges();
                }
            }

            System.GC.Collect();
        }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

using scope does it well. All objects instantiated from disposable interface,will dispose when instantiated in a using statement at the end of the scope. you don't need to do anything else.

Kamyar Nazeri
  • 25,786
  • 15
  • 50
  • 87
Saman Hajizade
  • 270
  • 1
  • 9
  • Thank you for your answer. But i used using scope for my entity. This may dispose_efEntities object, but might some others like datetime or list<> stay in memory and it dosen't solve my problem – Pourya Delnavaz Dec 24 '16 at 15:02
  • It isn't important because garbage collector dispose every object which they are not in use. – Saman Hajizade Dec 24 '16 at 17:00