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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:51:34+00:00 2026-06-15T13:51:34+00:00

I chose to return Task<T> and Task from my objects methods to provide easy

  • 0

I chose to return Task<T> and Task from my objects methods to provide easy consumation by the gui. Some of the methods simply wait for mutex of other kind of waithandles . Is there a way to construct Task from WaitHandle.Wait() so that I don’t have to block one treadpool thread for that.

  • 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-15T13:51:35+00:00Added an answer on June 15, 2026 at 1:51 pm

    There is a way to do this: you can subscribe to WaitHandle using ThreadPool.RegisterWaitForSingleObject method and wrap it via TaskCompletionSource class:

    public static class WaitHandleEx
    {
        public static Task ToTask(this WaitHandle waitHandle)
        {
            var tcs = new TaskCompletionSource<object>();
    
            // Registering callback to wait till WaitHandle changes its state
    
            ThreadPool.RegisterWaitForSingleObject(
                waitObject: waitHandle,
                callBack:(o, timeout) => { tcs.SetResult(null); }, 
                state: null, 
                timeout: TimeSpan.MaxValue, 
                executeOnlyOnce: true);
    
            return tcs.Task;
        }
    }
    

    Usage:

    WaitHandle wh = new AutoResetEvent(true);
    var task = wh.ToTask();
    task.Wait();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am downloading data from website using asynctask and my code for async task
I have the following code which does nothing but reading some values from a
from celery.decorators import task from celery.decorators import task @task() def add(x, y): r =
I am trying to return a string from my php file to my android
For my diploma thesis I chose to implement the task of the ICFP 2004
My task is to retrieve html strings from urls using Java. I know how
I have a program that reads objects (Tasks) from either a CSV file or
I'm unable to get the cursor to return updated information from the SQlite database.
I am trying to return an IEnumerable from a method that is backed by
$(a.close).click(function() { var id = $(this).attr(id); alert(id); $(this).parents(div.venue:first).fadeOut(Fast); return false; }); Any ideas why

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.