VB.net滞后于不同的机器

时间:2014-10-07 08:15:26

标签: vb.net timer lag

我写了一个小小的关键库存程序。基本上它使用INI文件来了解我们拥有哪些密钥以及哪些密钥已注销,由谁,由谁等。它在同一房间中最多4台计算机上运行并访问本地服务器上的ini文件。

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

当我在机器A上签出密钥并且同事在机器B,C或D上运行相同的程序时,签出的内容的更改不会显示4-10秒。

程序检查更新的方式是在加载时使用IO.File.Getlastwritetime(将其保存到带有visible = false的标签),然后每次定时器(每秒)都比较文件" getlastwritetime"到标签。如果它们不同,那么它会更新,如果它们是相同的,它什么都不做。

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

这是Timer1.tick的代码,我正在使用http://deepvbnet.blogspot.in/2008/07/how-to-read-from-ini-file.html的读/写ini代码

    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

0 个答案:

没有答案