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 243595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:56:04+00:00 2026-05-11T20:56:04+00:00

Edit Based on suggestions below to send the logic code GUI delegates, I came

  • 0

Edit

Based on suggestions below to send the logic code GUI delegates, I came up with code like this:

Action ClearFunction = new Action(()=>Invoke(new Action(delegate() { ResultsBox.Clear(); } ) ));

Is it possible to shorten this?


Here is part of my C# windows forms program.

When I started converting the code to use another thread, it started to feel very crufty as I spawned threads and created public methods wrapped in delegates so the logic code could actually use the GUI.

Please give suggestions on better idioms or improvements to the architecture. Thank you.

    // form1.cs
    public void ClearResultsBox()
    {
        ResultsBox.Clear();
    }

    public void PrintResults(string s)
    {
        ResultsBox.AppendText(s);
    }

    private void SearchButton_Click(object sender, EventArgs e)
    {
        var t = new Thread(() => SearchCore.Execute(DirectoryBox.Text, SearchBox.Text, this));
        t.Start();
    }

   // logic.cs
class SearchCore
{
    delegate void ClearFunction();
    delegate void AppendFunction(string a);

    static ClearFunction clear;
    static AppendFunction print;

    public static void Execute(string path, string searchterm, MainForm form)
    {
        clear = new ClearFunction(() => form.Invoke(new ClearFunction(form.ClearResultsBox)));
        print = new AppendFunction(s => form.Invoke(new AppendFunction(form.PrintResults), s));

        clear();  
  • 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-11T20:56:04+00:00Added an answer on May 11, 2026 at 8:56 pm

    I wouldn’t have a circular reference between the form and searchCore.
    why don’t you make the search logic talk back to form through a callback? that way the search doesn’t need to know about the form and is easier to test.

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

Sidebar

Ask A Question

Stats

  • Questions 155k
  • Answers 155k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to check for events that occur within… May 12, 2026 at 10:36 am
  • Editorial Team
    Editorial Team added an answer Check out http://www.ipinfodb.com/. You can get a latitude and longitude… May 12, 2026 at 10:36 am
  • Editorial Team
    Editorial Team added an answer BuzzAnn, Microsoft's documentation on the topic indicates that setting your… May 12, 2026 at 10:36 am

Related Questions

I'm using TPTP to profile some slow running Java code an I came across
I'm new to SVN. After working on a branch for a day or so,
I have a Django form that uses a different number of fields based on
Ok, I have a set of checkboxes for selecting criteria. For argument's sake, we'll

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.