Dim dtOr As New DataTable
Dim trdOr As Threading.Thread
Dim intMaxEtId As String
Delegate Sub LoadOrGrid()
Private Sub FillMyOrGrid()
dgvCustOrders.DataSource = dtOr
dgvCustOrders.Cursor = Cursors.Default
End Sub
Public Sub GetMaxOrId()
Dim SQLcon As New SqlConnection
SQLcon = Database.DataModule.GetSQLConnection()
Try
Dim sql As String = ("WITH CTEQuery(OrderID) as (SELECT TOP 5 OrderID from Acc_orders where OrderTypeID=5 and ActionTypeID=0 and CompanyID=1 ORDER BY OrderID) select MAX(OrderID) as LaOrderId from CTEQuery")
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, SQLcon)
Dim dtOrId As New DataTable
da.Fill(dtOrId)
intMaxOrId = dtOrId.Rows(0).Item(0).ToString
Catch ex As Exception
End Try
End Sub
Public Sub UpdateOrInquiry()
Dim SQLcon As New SqlConnection
SQLcon = Database.DataModule.GetSQLConnection
Try
Dim SQL As String = String.Empty
SQL = " update Acc_orders set ActionTypeID=1 where(OrderTypeID=5) and ActionTypeID=0 and CompanyID=1 and OrderID<=" & intMaxOrId
SQLcon.Open()
Dim command As New SqlCommand(SQL, SQLcon)
command.ExecuteNonQuery()
Catch ex As Exception
End Try
SQLcon.Close()
SQLcon.Dispose()
End Sub
Public Sub GetOrSQLOrders()
GetMaxOrId()
If intMaxOrId Is Nothing OrElse IsDBNull(intMaxOrId) Then
Exit Sub
Else
Dim SQLcon As New SqlConnection
SQLcon = Database.DataModule.GetSQLConnection()
Try
Dim sql As String = "select top 5 OrderID,phone,Amount,CreateDate,CompanyID,(select UserName from Acc_Accounts where Acc_Accounts.AccountID = Acc_orders.AccountID) as UserName from Acc_orders where OrderTypeID=5 and ActionTypeID=0 and CompanyID=1 and OrderID<=" & intMaxOrId
Dim daM As SqlDataAdapter = New SqlDataAdapter(sql, SQLcon)
daM.Fill(dtOr)
dgvCustOrders.DataSource = dtOr
UpdateOrInquiry()
Catch ex As Exception
End Try
End If
End Sub
the code is working fine and stable if its in the main thread but in multithreading not stable
some times it make update for the record before it show it in the datagrideview
and unstable things
I call the code from timer
Private Sub TBrain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBrain.Tick
Select Case cboNom.Text
LoadData()
StartMoSend()
IfRecharge()
End Sub
Private Sub LoadData()
If lblMobRow.Text = 0 And txtMobiNorNumber.Text.Trim = "" Then
GetOrSQLOrders()
End If
End Sub
thanks for your help
What I have tried:
I tryed all the code apove then I replace the
dgvCustOrders.Invoke(New LoadOrGrid(AddressOf FillMyOrGrid))
with
dgvCustOrders.DataSource = dtOr
its working and stable