none
When I use a Time in my project RAM is getting full RRS feed

  • Question

  • I'm using a Timer in my project, but every time that run myTimer.Tick, myApp use more memory than before. At start in used 63MB of RAM after 30 minutes it used 700MB. I see it used 700MB in Task Manager.

    private void Window_Loaded_1(object sender, RoutedEventArgs e)
    {    
        DispatcherTimer tmShowAlarm = new DispatcherTimer();
        tmShowAlarm.Tick += new EventHandler(ShowAlarm);
        tmShowAlarm.Interval = new TimeSpan(1000);
        tmShowAlarm.Start();
    }
    
    private void ShowAlarm(object Sender, EventArgs e)
    {
         string strDate = "2019/10/10";
         DatabaseContext oDatabaseContext = null;
         try
         {
             oDatabaseContext = new DatabaseContext();
             var varNote = oDatabaseContext.Notes.Where(_note => _note.NoteDate.CompareTo(strDate ) < 0);
    
             dgShowResult.ItemsSource = null;
             if (varNote.Count() > 0)
             {
                 dgShowResult.ItemsSource = varNote.ToList(); // this line use memory if I remove it, MyApp doesn't use more momory
                 dgShowResult.Visibility = Visibility.Visible;
             }
             else
             {
                 dgShowResult.Visibility = Visibility.Hidden;
             } 
    
             varNote = null;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            oDatabaseContext.Dispose();
            oDatabaseContext = null;
        }
    
    }

    When I remove dgShowResult.ItemsSource = varNote.ToList(); it doesn't use more memory.
    Thursday, October 31, 2019 7:15 PM

All replies