File.Exists對到不同的網芳時,會粉慢哦!

File.Exists粉慢

在VS 2003中使用File.Exists(filepath),當這個FilePath的電腦不存在時,就會粉慢,如

System.Io.File.Exists(“\\QKCP\XX\OK.aspx”)。

這樣就要花很多時間,所以使用上要小心哦!

其實試了以下幾種方式,都粉慢呢! 應該是在找 網芳就花了粉多的時間吧!

 


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Now
        System.IO.File.Exists("\\xx\xx\ok.aspx")
        TextBox2.Text = Now
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        On Error Resume Next
        TextBox1.Text = Now
        System.IO.File.Open("\\xx\xx\ok.aspx", IO.FileMode.Open)
        TextBox2.Text = Now
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = Now
        If Dir("\\xx\xx\ok.aspx") <> "" Then

        End If
        TextBox2.Text = Now
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        On Error Resume Next
        TextBox1.Text = Now
        Dim aryFiles() As String = System.IO.Directory.GetFiles("\\xx\xx\")
        For Each strFile As String In aryFiles
            If strFile = "ok.aspx" Then

            End If
        Next
        TextBox2.Text = Now
    End Sub

 

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^