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

  • SEARCH
  • Home
  • 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 5995237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:55:53+00:00 2026-05-22T23:55:53+00:00

I have a Windows Forms application that I’m working on, but I’m having trouble

  • 0

I have a Windows Forms application that I’m working on, but I’m having trouble when I start the application. The application should load saved information from a config file, and then check for new items. When I start the application, it starts looking for new items before it has finished loading saved items. Because of this the user is alerted of new items that are not really new, they just have not been loaded from the file yet.

The Form:

public class MainForm : Form
{
    A a;

    public MainForm()
    {
        InitializeComponent();
        a = new A();
        a.ItemsFound += new A.NewItemsFoundEventHandler(a_FoundItems);
        a.ItemsLoaded += new A.ItemsLoadedEventHandler(a_ItemsLoaded);
        a.LoadItems();
    }

    public void a_FoundItems(object sender, EventArgs e)
    {
        //Alert user of new items.
    }
    public void a_ItemsLoaded(object sender, EventArgs e)
    {
        //Update GUI with items loaded from file.
        this.UpdateTheGUI_ThisIsNotARealMethodInMyProgram();

        //Then look for new items.
        a.CheckForUpdates();
    }
}

The other object:

public class A
{
    public A(){}

    public void LoadItems()
    {
        //Load Items from save file...
        OnItemsLoaded(this);
    }

    public void CheckForUpdates()
    {
        //Check for new items...
        //If new items are found, raise ItemsFound event
        OnNewItemsFound(this,new EventArgs());
    }   

    public delegate void NewItemsFoundEventHandler(object sender, EventArgs e);
    public event NewItemsFoundEventHandler ItemsFound;
    protected void OnNewItemsFound(object sender, EventArgs e)
    {
        if(ItemsFound != null)
        {
            ItemsFound(sender,e);
        }
    }

    public delegate void ItemsLoadedEventHandler(object sender, EventArgs e);
    public event ItemsLoadedEventHandler ItemsLoaded;
    protected void OnItemsLoaded(object sender)
    {
        if(ItemsLoaded != null)
        {
            ItemsLoaded(sender,new System.EventArgs());
        }
    }
}

Should I have object A call it’s functions on a new thread, and lock so CheckForUpdates cannot be called if LoadItems is running, or is there a simpler way to do this that I’m missing?

EDIT:

I found the problem. I was clearing the List of items (so it would not grow forever), but I was only filling it with the newly found items. So every time I ran the application only the newest items where in the list, and all the older items were flushed out.

STUPID!!!

Thanks for the help though, and sorry for the crappy question.

  • 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-05-22T23:55:54+00:00Added an answer on May 22, 2026 at 11:55 pm

    Is there any reason why the check is not in the constructor?

    public MainForm()
    {
        InitializeComponent();
        a = new A();
        a.ItemsFound += new A.NewItemsFoundEventHandler(a_FoundItems);
        a.ItemsLoaded += new A.ItemsLoadedEventHandler(a_ItemsLoaded);
        a.LoadItems();
        a.CheckForUpdates();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Forms application that I wrote that does some monitoring of
I have a Windows Forms (.NET) application that can have multiple documents open simultaneously.
I have a client server based windows forms application that needs an administrator only
I have an application that displays an image inside of a Windows Forms PictureBox
I have a keyboard focus problem with Windows Forms application that hosts WPF UserControls.
I have a windows form application that uses a Shared class to house all
I have several .NET Windows Forms applications that I'm preparing to convert into a
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser
I have written a C# Windows Forms application to merge the files and folders
I have a .NET 2.0 Windows Forms application. Where is the best place the

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.