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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:44:29+00:00 2026-06-01T19:44:29+00:00

I am new to c#; I have mainly done Java. I want to implement

  • 0

I am new to c#; I have mainly done Java.

I want to implement a timeout something along the lines:

int now= Time.now();
while(true)
{
  tryMethod();
  if(now > now+5000) throw new TimeoutException();
}

How can I implement this in C#? 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-01T19:44:30+00:00Added an answer on June 1, 2026 at 7:44 pm

    One possible way would be:

    Stopwatch sw = new Stopwatch();
    sw.Start();
    
    while(true)
    {
        tryMethod();
        if(sw.ElapsedMilliseconds > 5000) throw new TimeoutException();
    }
    

    However you currently have no way to break out of your loop. I would recommend having tryMethod return a bool and change it to:

    Stopwatch sw = new Stopwatch();
    sw.Start();
    
    while(!tryMethod())
    {
        if(sw.ElapsedMilliseconds > 5000) throw new TimeoutException();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a similar question a few days ago, but now I have new
i mainly use PHP and I have been coding using it for a while.
I am a brand new Java developer (I have been working in asp.net) and
Prelim caveat: I am very new to js and have mainly gotten by through
I want to use a custom object as a Dictionary key, mainly, I have
I have not done Perl for about 8 years and now I'm going into
As the university starts, I have a new module called JAVA! I already have
Looks like operator new and operator new[] have exactly the same signature: void* operator
i have new webcam. The software of the webcam can give out the webcam
I have new problem. My code: .method public static void Main() cil managed {

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.