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

The company I am working for has a base app that they reskin and
My company uses the following algorithm to hash passwords before store it in the
My company is using CVS as our de-facto standard for source control. However, I've
My company has developed a long standing product using MFC in Visual C++ as
Our company is currently writing a GUI automation testing tool for compact framework applications.
The company I used to work with has two developers working fulltime, and a
The company I work for makes hardware that communicates to the computer though a
The company I work for is wanting to add blog functionality to our website
My company is using Visual SourceSafe (VSS) and Visual Studio 2005 (soon 2008). They
The company I'm currently working for is using Selenium for Uniting-Testing our User Interface.

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.