Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:19:54+00:00 2026-06-13T01:19:54+00:00

I have a WPF app with an event log. I have an EventLog class

  • 0

I have a WPF app with an event log. I have an EventLog class I populate with saved events from an XML file when the app starts

namespace MyApp.Agent.EventLogging
{
    public enum EventType
    {
        Infomation,
        Error
    }
    public class EventLog
    {
        public String Image { get; set; }
        public DateTime EventDate { get; set; }
        public String EventText { get; set; }
    }
}

public List<EventLog> GetSavedEvents()
{
   string file = XmlUtilities.GetXmlLocation() + "\\Events.xml";
   List<EventLog> elog = new List<EventLog>();
   try
   {
       if (File.Exists(file))
       {
          Serialize<List<EventLog>> ser = new Serialize<List<EventLog>>();
          elog = ser.DeserializeDocToObj(file);
       }
   }
   catch
   {
          throw new InvalidEventLogException(ConfigurationManager.AppSettings.Get("EventLogFileInvalid"));
   }
 return elog;
}

I then convert this into an observable collection that a listview is bound to

List<EventLog> _evtLog = new List<EventLog>();
ObservableCollection<EventLog> _eventLog = new ObservableCollection<EventLog>();
_evtLog = logger.GetSavedEvents();
_evtLog.ForEach(x => _eventLog.Add(x));

I read that this is how it has to been done (although it seems a long winded way)

As the app is running new events are added to the observable collection. When the app closes I reverse this process to save the events.

While this works fine if there are only a few saved events as the list is getting bigger so the time it takes to do this is getting unrealistic (240K events is taking 7 secs). Ok first question you may ask is why would I want that many events anyway, truth is I don’t but it does highlight that I am not doing this the best way?

So my questions are:

Do I really need to populate the observable collection? Can I not make _evtLog Observable without populating one from the other?

Can I restrict these lists to X events based on the date of the event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:19:55+00:00Added an answer on June 13, 2026 at 1:19 am

    You could easily change GetSavedEvents to serialize and deserialize an ObservableCollection<EventLog> instead of a List<EventLog>.

    Having said that, the code to convert the list to an observable collection looks strange. Why aren’t you just using the appropriate constructor?

    _eventLog = new ObservableCollection<EventLog>(logger.GetSavedEvents());
    

    The problem with using Add is that for each item being added you raise an event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF test app for evaluating event-based serial port communication (vs. polling
In my WPF app (csharp) I have an event handler that when triggered will
I have a WPF app that binds a DataGrid to an XML document using
I am writing a home WPF app that is obtaining a file from a
I have WPF app with 2 windows - whats the best way to syncronise
I have a WPF App that implements a ListView. I would like to show
I have a WPF app in which I need to programatically manipulate at runtime.
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have a wpf app that needs to communicate(exchange data) with a custom designed
We have a WPF app that allows our users to download encrypted content and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.