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

Does anyone have any recommendations of tools that can be of assistance with moving
I have a question on the types that can be returned by a WCF
Does anyone have any suggestions as to how I can clean the body of
Do you have any experience with T4 and T4 Editor ? Can you compare
Well i need to make it so any user can have a foo.com/username in
in the System.Linq namespace, we can now extend our IEnumerable's to have the Any()
I have an application where users can upload video files of any size, and
I have a N-Ary non sorted in any way tree and each node can
I want to have CListCtrl.EditLabel() for any column of the list. How can I
I have a set of options, some orthogonal (can be combined in any combination),

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.