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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:52:30+00:00 2026-05-16T13:52:30+00:00

How can i have any kind of data returned from a method or property

  • 0

How can i have any kind of data returned from a method or property within a time frame, and if any data is returned within that time frame an exception is thrown?

Pretty much I have a simple method that will perform a simple task, once performed the method returns a value, and if any value is returned within 100 milliseconds I want that the method be aborted and an exception be thrown, for instance a TimeoutException for example, any kind of exception, as long it does the task.

  • 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-16T13:52:31+00:00Added an answer on May 16, 2026 at 1:52 pm

    If you are on .NET 3.5 and can’t use Parallel Extensions, you can use asynchronous delegates. This has the added benefit of rethrowing exceptions thrown by the method on the calling thread. The timeout logic in this example relies on a WaitHandle, as mentioned by leppie.

    public static T EvaluateAsync<T> (this Func<T> func, Timespan timeout)
    {
      var result = func.BeginInvoke(null, null);
    
      if (!result.AsyncWaitHandle.WaitOne(timeout))
           throw new TimeoutException ("Operation did not complete on time.");
    
      return func.EndInvoke(result);
    }
    
    static void Example()
    {
       var myMethod = new Func<int>(ExampleLongRunningMethod);
    
      // should return
      int result = myMethod.EvaluateAsync(TimeSpan.FromSeconds(2));
    
      // should throw
      int result2 = myMethod.EvaluateAsync(TimeSpan.FromMilliseconds(100));
    }
    
    static int ExampleLongRunningMethod()
    {
      Thread.Sleep(1000);
      return 42;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one tell me an opensource js library that can have a real-time
Does anyone have any recommendations for tools that you can add to Eclipse, Netbeans
Do MySQL have any function by which I can split data of a column
I have a question on the types that can be returned by a WCF
if i have stated data in my php variable, how i can copy from
I have the following kind of data returned to me in xml format (many
I have a Jquery Mobile collapsible set , which can have any number of
Can I have any way to know which is the depth of a child
Anyone have any ideas what I can do? Please reserve commenting about using 1.1
Does anyone have any idea on how can you create a product filtering query

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.