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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:05:32+00:00 2026-06-14T17:05:32+00:00

If I have an interface such as: using System.Threading.Tasks; … public interface IFoo {

  • 0

If I have an interface such as:

using System.Threading.Tasks;

...

public interface IFoo
{
  Task doIt();

  Task<bool> doItAndReturnStuff();
}

and one of the classes implementing this interface just happens to not require async methods, how can i correct override these functions?

In other words, how do I correctly return “void” and “bool” wrapped in Task objects?

For example:

public class FooHappensToNotNeedAsync : IFoo
{
  public override Task doIt()
  {
    // If I don't return anything here, I get
    // error that not all code paths return a value.
    // Can I just return null?
  }

  public override Task<bool> doItAndReturnStuff()
  {
    // If I want to return true, how to I do it?
    // This doesn't work:
    return true;
  }
}

NOTE – I can’t strip the Task stuff completely because some of the classes that implement this interface are in fact asynch.

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-06-14T17:05:34+00:00Added an answer on June 14, 2026 at 5:05 pm

    It’s not clear what you’re trying to achieve, but one approach (which would look the most like “normal” code) is probably just to make them async methods anyway:

    public async Task DoIt()
    {
        // No-op
    }
    
    public async Task<bool> DoItAndReturnStuff()
    {
        return true;
    }
    

    Without any await expressions, the method will complete synchronously anyway. You’ll get a warning on each method, but you could disable that just for this piece of code using a #pragma.

    Alternatively – and I guess more simply in terms of not requiring a #pragma to disable warnings – would be to use Task.FromResult:

    public Task DoIt()
    {
        // Returns a Task<bool>, but that's okay - it's still a Task
        return Task.FromResult(true);
    }
    
    public Task<bool> DoItAndReturnStuff()
    {
        return Task.FromResult(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface in some referenced third-party assembly, such as: public interface ITextHandler
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {
Suppose I'm implementing an MVP pattern and I have a view interface as such:
I have several server controls that implement the IValidator interface. As such, they have
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have an interface, written in C#, defined as this : public interface IWidget
I have this following interface : public interface FruitDetails { public String getFruitName(); }
When using this object model: interface IInterface {} class Impl : IInterface { public
I have interface IConfigurationSource { .... } and class FileConfigurationSource : IConfigurationSource { FileConfigurationSource(string
I have two questions 1) my interface i have interface called IRegister and within

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.