IO.File.Exists 可以用来检查 .Net 中的服务器是否正常运行吗?

Can IO.File.Exists be use to check if a server is up in .Net?

我正在创建一个服务来创建一个文本文件,该文件可以被其他软件远程读取(这个文件是在多个服务器上创建的),

当需要读取文件时,我尝试从定义的主服务器读取它,如果我不能读取它,我假设服务器已关闭或没有响应,然后尝试从辅助服务器获取它,

目前我对主服务器上的文件执行 IO.File.Exists 检查,如果 returns 为真,我将读取该文件,否则我将在辅助服务器上执行相同的检查。

Dim filepath as String

If IO.File.Exists("\<Primary server>\<Folder>\<file>") Then
    filepath = "\<Primary server>\<Folder>\<file>")
Else
    filepath = string.empty
End if

If not filepath is string.empty then
    If IO.File.Exists("\<Secondary server>\<Folder>\<file>") Then
        filepath = "\<Secondary server>\<Folder>\<file>")
    Else
        filepath = string.empty
    End if
End if

此检查是否足以确定服务器是否可用,或者我是否应该执行进一步测试?

谢谢

根据您的需要,这应该没问题。但是切记,不要直接检查服务器是否可用,因为如果你没有任何权限,你检查也会失败。或者如果服务器可用,但 directory/file 不存在,您的检查甚至会失败。

如果文件共享处于活动状态,这可能会起作用。 否则您可能需要找到其他方式来读取文件。

客户端 <-> 服务器应用程序