Making main form unclickable during from UI Update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 85ssp
    New Member
    • Mar 2008
    • 6

    Making main form unclickable during from UI Update

    I have a server applicatoin that has a multitude of labels related to the clients connected to it. When I have a number near 50 clients and i recieve a updatated status from each of the clients at once the labels are updated to the current status. (basically a label color is changed depending on status), this operation causes the mainform to freeze until it can process all of the messages recieved.

    I have tried everything possible to make the form update asyncronously without this hang but cannot get it to work. Since each client thread runs the same update function i placed in a multitude of invoke code to make it update but there has been no change.

    So my next idea was to make the from unclickable until its ready but am unsure how to do this? anyone got any ideas?

    example of process:

    [CODE=vbnet]server:
    sendtoclients(" GETSTATUS")
    client:
    client("RETURNS TATUS|GREEN")
    server:
    case "RETURNSTAT US"
    If Not statusdict.Cont ainsKey(sender. WS) Then
    statusdict.Add( sender.WS, dataArray(1))
    Else
    statusdict.Item (sender.WS) = dataArray(1)
    End If
    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''''''
    UpdateUI()
    TargetHandler.B eginInvoke(Call backHandler, Nothing)

    '''''old method call 'readstatusdict oinary()
    end select

    sub readstatusentry ()
    Dim entry As DictionaryEntry

    Dim comp As String
    Dim status As String
    Dim ILoop As Integer = 0
    Dim ALoop As Integer = 0
    Dim green As Integer = 0
    Dim red As Integer = 0

    'nulls(display)
    loggedInLabel.T ext = "0"
    LockedLabel.Tex t = "0"

    'HERE is where it changes label color
    Try
    For Each entry In New System.Collecti ons.Hashtable(s tatusdict)
    ALoop = 0
    comp = entry.Key.ToStr ing
    status = entry.Value.ToS tring
    For ILoop = 0 To 69
    If comp = LabelArray(ALoo p).Text Then
    Select Case status.ToLower
    Case "red"
    LabelArray(ALoo p).BackColor = Color.Red
    red = red + 1
    green = green - 1
    lockedlabel.Tex t = red.ToString
    Case "green"
    LabelArray(ALoo p).BackColor = Color.Green
    green = green + 1
    red = red - 1
    loggedInLabel.T ext = green.ToString
    End Select
    PNRLabel.Text = gray.ToString
    End If
    ALoop = ALoop + 1
    Next
    Next
    Catch ex As Exception
    MsgBox(ex.ToStr ing)
    End Try
    end sub



    '*** create delegate object to execute method asynchronously
    Private TargetHandler As readstatusentry Handler _
    = AddressOf readstatusentry

    '*** create delegate object to service callback from CLR
    Private CallbackHandler As AsyncCallback _
    = AddressOf MyCallbackMetho d

    '*** callback method runs on worker thread and not the UI thread
    Sub MyCallbackMetho d(ByVal ar As IAsyncResult)
    Try

    UpdateUI()
    Catch ex As Exception

    MsgBox("Error: " & ex.Message)
    UpdateUI()
    End Try
    End Sub

    '*** can be called from any method on form to update UI
    Sub UpdateUI()
    '*** check to see if thread switch is required
    If Me.InvokeRequir ed Then
    Dim handler As New UpdateUIHandler (AddressOf readstatusentry )

    Me.BeginInvoke( handler)
    Else
    readstatusentry ()
    End If
    End Sub

    '*** delegate used to switch control over to primary UI thread
    Delegate Sub UpdateUIHandler ()
    Delegate Sub readstatusentry Handler()[/CODE]
    Last edited by Killer42; Mar 14 '08, 12:51 AM. Reason: Added CODE=vbnet tag
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by 85ssp
    ...

    So my next idea was to make the from unclickable until its ready but am unsure how to do this? anyone got any ideas? ...
    Couldn't you just disable it?

    [CODE=vb]me.enabled=fals e[/CODE]

    Comment

    • 85ssp
      New Member
      • Mar 2008
      • 6

      #3
      Originally posted by kadghar
      Couldn't you just disable it?

      [CODE=vb]me.enabled=fals e[/CODE]

      where should I disable it? if i disable the form at the begining of readstatusentry and then enable it at the end, when another client calls function it will just run the code again and again and again. Just like changing the label color.

      Comment

      • 85ssp
        New Member
        • Mar 2008
        • 6

        #4
        i went ahead and instituted a counter to count the cleint messages and then update the form, this works in a specific circumstance when the server comes up and individual clients connect.

        If the server crashes, and you relaunch the server, all clients try to connect at once and the server is not recieving all of the transmissions, roughly missing 3 clients.

        Anyone have any idea on how i may go about solving this.

        Comment

        • Sick0Fant
          New Member
          • Feb 2008
          • 121

          #5
          Maybe there's something I'm not understanding, but can't you just create an event and listen for it in your main form?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Wouldn't it make sense to have a timer update the labels periodically, independently of when the messages are received? Perhaps once per second, or whatever seems appropriate.

            Comment

            • 85ssp
              New Member
              • Mar 2008
              • 6

              #7
              I went ahead and institiuted a timer to update the ui, but i dont believe this to be my issue now, it appears the server is dropping messages sent to it over the network, basically not recieving everything it needs too when 50 clients send at the same time, any idea how to clear this up? I'm transmitting on port 6000, could this be the issue?

              Comment

              Working...