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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:48:37+00:00 2026-05-27T07:48:37+00:00

My company’s code base contains the following C# line: bool pathExists = Directory.Exists(path); At

  • 0

My company’s code base contains the following C# line:

bool pathExists = Directory.Exists(path);

At runtime, the string path happens to be the address of a folder on the company’s intranet – something like \\company\companyFolder. When the connection from my Windows machine to the intranet is up, this works fine. However, when the connection goes down (as it did today), executing the line above causes the application to freeze completely. I can only shut the application down by killing it with the Task Manager.

Of course, I would rather have Directory.Exists(path) return false in this scenario. Is there a way to do this?

  • 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-27T07:48:37+00:00Added an answer on May 27, 2026 at 7:48 am

    There is no way to change the behavior of Directory.Exists for this scenario. Under the hood it’s making a synchronous request over the network on the UI thread. If the network connection hangs because of an outage, too much traffic, etc … it will cause the UI thread to hang as well.

    The best you can do is make this request from a background thread and explicitly give up after a certain amount of time elapses. For example

    Func<bool> func = () => Directory.Exists(path);
    Task<bool> task = new Task<bool>(func);
    task.Start();
    if (task.Wait(100)) {
      return task.Value;
    } else {
      // Didn't get an answer back in time be pessimistic and assume it didn't exist
      return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My company doesn't use Apache, so we've spun up our own socket code. In
The company I am working for has a base app that they reskin and
Our company has a requirement to build a web based business line solution with
Our company has a share point document server where the UNC looks something like
Our company produces cross-platform software and we have Bamboo instance which is building projects
The company i am working for is implementing Share-point with reporting servers that runs
My company provide services to other websites. I would like to be able to
My company is using SQL Server Compact to store and manage a local database
My company is cursed by a symbiotic partnership turned parasitic. To get our data
My company is redoing our website over the next few months, going from a

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.