不同机器上的VB.net滞后

不同机器上的VB.net滞后,vb.net,timer,lag,Vb.net,Timer,Lag,我写了一个小的关键库存计划。基本上,它使用一个INI文件来知道我们拥有什么密钥,哪些密钥被签出,签给谁,由谁签出,等等。它在同一个房间的多达4台计算机上运行,并访问本地服务器上的INI文件 当我签出或签入密钥时,它会立即显示更改。如果我在同一台机器上运行同一程序的两个实例,同样是即时的 当我在机器a上注销密钥时,一位同事正在机器B、C或D上运行相同的程序,注销内容的更改在4-10秒内不会显示出来 程序检查更新的方法是在加载时使用IO.File.Getlastwritetime将其保存到visib

我写了一个小的关键库存计划。基本上,它使用一个INI文件来知道我们拥有什么密钥,哪些密钥被签出,签给谁,由谁签出,等等。它在同一个房间的多达4台计算机上运行,并访问本地服务器上的INI文件

当我签出或签入密钥时,它会立即显示更改。如果我在同一台机器上运行同一程序的两个实例,同样是即时的

当我在机器a上注销密钥时,一位同事正在机器B、C或D上运行相同的程序,注销内容的更改在4-10秒内不会显示出来

程序检查更新的方法是在加载时使用IO.File.Getlastwritetime将其保存到visible=false的标签上,然后每当计时器每秒运行时,它都会将文件Getlastwritetime与标签进行比较。如果它们不同,则会更新,如果它们相同,则不会执行任何操作

知道我应该从哪里开始寻找这个滞后吗?可能是服务器问题吗

这是Timer1.tick的代码,我使用的是来自的读/写ini代码


你能展示一下你代码的相关部分吗?您读取和执行检查的部分?添加了计时器1。勾选代码您最好使用存储在服务器上并与每台机器共享的数据库。字符串比较和连接非常昂贵,INI文件的管理也是如此。有趣的是GetLastWriteTime返回的是日期时间而不是字符串。也许它们是一样的,但你是在比较苹果和香蕉。错误的方法,使用DateTime全局变量进行此类检查。我建议您将文件粘贴到运行VS的机器以外的机器上,并逐步查看代码以了解您的速度慢在哪里。如果文件夹中有很多文件,那么在远程计算机上执行的GetFiles操作会比较慢。
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim TimeCheck As String = IO.File.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/keys.ini")
    If TimeCheck <> Label5.Text Then
        ListBox1.Items.Clear()
        ComboBox1.Items.Clear()

        str1 = "NumOfKeys"
        Call readIniFile()

        Dim OneTime As String = strdata.ToString
        Dim numberofkeys As Integer = Convert.ToInt32(OneTime)

        For i = 1 To numberofkeys
            str1 = "Key" & i & "Out"
            Call readIniFile()
            Dim isKeyOut As String = strdata.ToString
            If isKeyOut = "True" Then
                str1 = "Key" & i & "Name"
                Call readIniFile()
                Dim KeyName As String = strdata.ToString

                str1 = "Key" & i & "Unit"
                Call readIniFile()
                Dim string1 As String = strdata.ToString

                str1 = "Key" & i & "Rent"
                Call readIniFile()
                Dim string2 As String = strdata.ToString

                str1 = "Key" & i & "User"
                Call readIniFile()
                Dim string3 As String = strdata.ToString

                str1 = "Key" & i & "Date"
                Call readIniFile()
                Dim string4 As String = strdata.ToString

                str1 = "Key" & i & "Time"
                Call readIniFile()
                Dim string5 As String = strdata.ToString

                ListBox1.Items.Add(LSet(KeyName, 20) + " - " + string1 + " - " + string2 + " - " + string3 + " - " + string4 + " - " + string5)
            ElseIf isKeyOut = "False" Then
                str1 = "Key" & i & "Name"
                Call readIniFile()
                Dim thisKeysName As String = strdata.ToString
                ComboBox1.Items.Add(thisKeysName)
            End If

        Next
        Dim FileTime As String = IO.File.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/keys.ini")
        Label5.Text = FileTime
    End If


    Dim escortTime As String = IO.Directory.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/Escort")
    If escortTime <> Label7.Text Then
        ListBox2.Items.Clear()
        For Each foundfile In My.Computer.FileSystem.GetFiles("G:/BFAS/DPS/Comm Center/TEST/Escort/")
            If foundfile = "G:/BFAS/DPS/Comm Center/TEST/Escorthistory.txt" Then
                'do nothing
            Else
                Dim Infomation As String = My.Computer.FileSystem.ReadAllText(foundfile)
                ListBox2.Items.Add(Infomation)
            End If
        Next

        Label7.Text = IO.Directory.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/Escort")
    End If

    Dim alarmtime As String = IO.Directory.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/Alarms")
    If alarmtime <> Label8.Text Then
        ListBox3.Items.Clear()
        For Each foundfile In My.Computer.FileSystem.GetFiles("G:/BFAS/DPS/Comm Center/TEST/Alarms/")
            Dim Infomation As String = My.Computer.FileSystem.ReadAllText(foundfile)
            ListBox3.Items.Add(Infomation)

        Next
        Label8.Text = IO.Directory.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/Alarms")
    End If



    Dim turnovertime As String = IO.File.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/turnover.txt")
    If Label9.Text <> turnovertime Then
        Dim newTO As String = My.Computer.FileSystem.ReadAllText("G:/BFAS/DPS/Comm Center/TEST/turnover.txt")
        TextBox3.Text = newTO
        Label9.Text = IO.File.GetLastWriteTime("G:/BFAS/DPS/Comm Center/TEST/turnover.txt")
    End If
    End Sub