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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:11:42+00:00 2026-05-26T03:11:42+00:00

I built an Async task service executor that execute tasks by external request. Each

  • 0

I built an Async task service executor that execute tasks by external request.

Each task contains the function void run(), so any programmer who want’s to add a task to the system needs to inherit From BaseTask.

    interface ITask{
       void run();
    }
    abstract BaseTask : ITask{
       //force "run()" to set Result
       public ResultContainer Result {set; get;}
       void run();
    }

    class SomeTask : BaseTask {
       void run(){
           ////run the operation here, in the end, set the result.
           //force the programmer to set the Result;
           this.Result = new ResultContainer("task ok");
       }
    }

For internal reasons, the run() must be void.

Is there any way that I can force a programmer who wants to add a task to invoke Result in BaseTask and set its value?
Do you think it is a bad practice?

Thanks

  • 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-26T03:11:42+00:00Added an answer on May 26, 2026 at 3:11 am

    Yes, this is something to be avoided. Rules like this should be in place such that they’re enforced by the compiler (rather than convention) when possible and practical.

    In your case, you should do something like this:

    public abstract class BaseTask
    {
        public void Run()
        {
            Result = RunInternal();
        }
    
        public ResultContainer Result { get; set; }
    
        protected abstract ResultContainer RunInternal();
    }
    

    This will accomplish what you want semantically (that invoking the Run function externally will always cause the Result property to be set), and it forces the developer who inherits from BaseTask to supply the value that’s being used. The only difference is that they will override (or, rather, implement) the RunInternal function instead of Run.

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

Sidebar

Related Questions

I'm working on creating an async handler for ASP.NET that will execute a slow
In my .NET application built with WPF and C# I call an async function
I've built a page using jQuery that uses an async Ajax call. I'm trying
The built-in Math.Pow() function in .NET raises a double base to a double exponent
I built a Winform app several months ago that schedules appointments for repair techs.
I've implemented a task using the async Sockets pattern in Silverlight 3. I started
I've built a log-in composite that I am displaying in my application entry-point to
Built an iPhone app that generates a random number to a label when a
How do I use F#'s built-in support for async operations classes exposing the Event-based
I have built a component library that includes an executive class which does work

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.