0
我有多個客戶端和一臺通過TCP傳遞對象更新的服務器。如何使用事件和TCP同步數據與數據庫
基本上,服務器運行訪問對象的算法,但這些算法可能會在更新通過TCP發送時更改。
我已設置標誌來檢查對數據庫的更新,並且只在本地內存或數據庫服務器之間的數據有差異時才發送更新。問題是如果對象在迭代時發生更改。
的算法運行的後臺線程和代碼架構概括如下所示,它是事件驅動的:
算法後臺線程:
Private algorithm As New NewAlgorithmTest
Private Sub bg_workerAlgorithm_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bg_workerAlgorithm.DoWork
algorithm.RunAlgorithm()
End Sub
Private Sub bg_workerAlgorithm_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bg_workerAlgorithm.RunWorkerCompleted
bg_workerAlgorithm.RunWorkerAsync()
End Sub
TCP消息的收到來自客戶端:
Private Sub Client_MessageReceived(sender As Object, e As TcpClient.MessageRecievedEventArgs)
Dim message As String = e.Message
'figure out which object to update based off message and set it as updatedObject
dim updatedObject
updatedObject.GetLatest()
End Sub
我該怎麼去abo解決這個問題?