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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:00:35+00:00 2026-06-04T15:00:35+00:00

I am having trouble setting a bool to a method that returns a bool.

  • 0
  • I am having trouble setting a bool to a method that returns a bool.
  • I am using a Queue of type Task and am passing the method to the Queue as a new Task.
  • How do I set a bool based off of the method call that is used inside of Task.Start() ?
  • How do I re-execute a Task, so that I may call Task.Start() multiple times?

    public static void Main(string[] args)
    {
        Console.WriteLine("Performing Queue<Task> q = new Queue<Task>();");
        Queue<Task> q = new Queue<Task>();
        Console.WriteLine("Finished Queue<Task> q = new Queue<Task>();");
        Console.WriteLine("Performing q.Enqueue(new Task(() => hello(\"world\") ) );");
        q.Enqueue(new Task(() => print("hello world") ) );
        Console.WriteLine("Finished q.Enqueue(new Task(() => hello(\"world\") ) );");
        Console.WriteLine("Performing Task peek = q.Peek();");
        Task peek = q.Peek();
        Console.WriteLine("Finished Task peek = q.Peek();");
        Console.WriteLine("Performing peek.Start();");
        //bool temp = peek.Start(); // does not set temp to true, how do I accomplish this?
        peek.Start(); // Works, but does not return true as print() should return true, how do I accomplish this?
        Console.WriteLine("Finished peek.Start();");
        Console.WriteLine("Performing Task dequeue = q.Dequeue();");
        Task dequeue = q.Dequeue();
        Console.WriteLine("Finished Task dequeue = q.Dequeue();");
        Console.WriteLine("Performing dequeue.Start();");
        //bool temp2 = dequeue.Start(); // does not set temp2 to true, how do I accomplish this?
        dequeue.Start(); // How do I make a Task reexecute?
        Console.WriteLine("Finished dequeue.Start();");
    
    }
    public static bool print(string text)
    {
        Console.WriteLine("print(" +text +")");
        return true;
    }
    
  • 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-04T15:00:37+00:00Added an answer on June 4, 2026 at 3:00 pm

    Here is an example of how to get a return value from a Task:

    http://msdn.microsoft.com/en-us/library/dd537613

    The MSDN article for Task (http://msdn.microsoft.com/en-us/library/dd270682.aspx) says that:

    A task may only be started and run only once. Any attempts to schedule
    a task a second time will result in an exception.

    I would recommend finding a way to rewrite your code using Task.Factory.StartNew() instead of new Task().Start. Here is a good article on the difference:

    http://blogs.msdn.com/b/pfxteam/archive/2010/06/13/10024153.aspx

    Why not queue up enum values instead of the Tasks themselves, and then write a small function to run a task based on the enum value. It could look something like:

    public static void StartTask(Actions action)
    {
        if (action == Actions.Print)
        {
            Task t = new Task(() => print("hello world"));
            t.Start();
        }
    }
    

    Incorporate the return values based on the first example and then you’re all set.

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

Sidebar

Related Questions

I'm using KVC to iterating through a few views. Having trouble setting BOOL properties:
I'm having trouble setting up a new server using Moonshine and Capistrano. It seems
I'm having trouble setting the path to a DLL that is not in the
I am using jQuery UI Selectmenu and am having trouble setting the value of
I'm having trouble setting up a new eclipse installation with the -vm option. I'm
Java newbie here, I'm having trouble setting a new line in this code: String
I'm using Model-View-Presenter framework. When Loading a page, I'm having trouble setting the selected
I've been having some trouble with Snow Leopard's new block-based API for observing notifications
Im having Trouble setting up an in memory database using RavenDB. The error I
Having trouble setting a block template in Magento's layout xml. I'm attempting to set

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.