Results 1 to 4 of 4

Thread: [RESOLVED] [2005] How to time out a procedure

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved [RESOLVED] [2005] How to time out a procedure

    Good day all

    I am trying to check if a file exists for a path, but how can i put a timer on this so that if it is not working then it will time out instead of taking a long long time to send the error message?

    Cheers

    Code:
    Sub GetInfo()
            If System.IO.File.Exists(DataSourcePath) = True Then
              'Do something
    Else
    Msgbox "Error: file cannot be fould"
    frm.Label1.text = "ERROR"
    End if
        End Sub
    If you find my thread helpful, please remember to rate me

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to time out a procedure

    How can File.Exists take a long time? Either the file exists or it doesn't. The result should be instantaneous. I don't think that method can even throw an exception.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] How to time out a procedure

    it takes a long time as sometimes people do not have the network drive mapped or have access to it
    If you find my thread helpful, please remember to rate me

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to time out a procedure

    I just tried File.Exists on a disconnected network drive and it took 0.0000673 seconds. Anyway, I'll take your word for it that there are circumstances where it doesn't return immediately. You can't do anything about that though. It's a blocking method so there's nothing you can do to force it to return. The only possibility would to execute it in a background thread and forcibly terminate that thread if it didn't complete within a certain time. That seems pretty extreme for something so simple though. I think a better option would be to make sure users have access to the specific resources first.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width