2012-08-01, 12:20
Can anyone tell me where I'm going wrong here please....
I have the above code but everytime it tries to read data (as indicated) the program just freezes and never completes the read instruction.
If XBMC isn't running there is no issue as obviously there is no connection but if it IS running, it freezes until there is some activity in XBMC; by activitiy I mean a notification like Player.OnPlay or Player.OnPause. Obviously, what's happeneing is a synchronous read rather than an asynchronous one so how can I change it? The code is called from a timer which has an interval of 1 second (1000 ms).
EDIT: Nevermind. Think I had a lapse in logic and added a ReadTimeout.
Code:
Try
If (xbmcClient.Connected) Then
xbmcStream = xbmcClient.GetStream()
If xbmcStream.CanRead Then
Dim myReadBuffer(1024) As Byte
Dim myCompleteMessage As StringBuilder = New StringBuilder()
Dim numberOfBytesRead As Integer = 0
Do
numberOfBytesRead = xbmcStream.Read(myReadBuffer, numberOfBytesRead, myReadBuffer.Length) <-- FREEZES here...
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead))
Loop While xbmcStream.DataAvailable
xbmcMethod = jsonParser(myCompleteMessage.ToString(), "method")
Select Case xbmcMethod
Case "Player.OnPlay"
debugMessage("xbmcMethod: Player.OnPlay")
currentState = "Playing..."
statusWindow.ShowDialog()
Case "Player.OnPause"
debugMessage("xbmcMethod: Player.OnPause")
currentState = "Paused..."
statusWindow.ShowDialog()
Case Else
debugMessage("xbmcMethod: " + xbmcMethod)
End Select
Else
debugMessage("Unable to read from XBMC Stream")
End If
Else
xbmcConnect()
End If
Catch ex As Exception
debugMessage("xbmcMethod Exception: " + ex.Message)
End Try
I have the above code but everytime it tries to read data (as indicated) the program just freezes and never completes the read instruction.
If XBMC isn't running there is no issue as obviously there is no connection but if it IS running, it freezes until there is some activity in XBMC; by activitiy I mean a notification like Player.OnPlay or Player.OnPause. Obviously, what's happeneing is a synchronous read rather than an asynchronous one so how can I change it? The code is called from a timer which has an interval of 1 second (1000 ms).
EDIT: Nevermind. Think I had a lapse in logic and added a ReadTimeout.