Android Question streamer_RecordBuffer not seeing value of Global Variable.

Discussion in 'Android Questions' started by Isa Paine, Jan 30, 2015.

  1. Isa Paine

    Isa Paine Member Licensed User

    I have 2 threads not see each other setting a global variable.


    When tmrTemp_Tick fires it disables itself and calls stop recording.
    stopRecording sets audio streamer.stopRecording and the Global IsRecording = False
    The problem is, there is still data in the audio buffer so streamer_RecordBuffer executes, and thinks IsRecording is true, even though IsRecording was set false by stopRecording.

    Why does streamer_RecordBuffer think IsRecording = true?
    How can I IsRecording so all objects see the updated vale?

    Code:
    Sub tmrTemp_Tick
        tmrTemp.Enabled = 
    False   
        stopRecording   
    End Sub

    Sub stopRecording

        
    Dim dateString As String

        streamer.stopRecording

        IsRecording = 
    False
       
        
    DoEvents
        DisplayResult
       
    End Sub

    Sub streamer_RecordBuffer (Buffer() As Byte)
        
    Dim tempString As String
        
    Dim temperature As Double
       
        temperature = AudioUtils.GetTemperature(Buffer)
        tempString = temperature
        tempString = tempString.SubString2(
    0,tempString.IndexOf(".") + 2)
        surveyTransaction.temperatureMeasured = tempString
       
        
    DoEvents
        
    If IsRecording Then
            DisplayProcessingPanel(PROCESSING)
        
    End If
       
    End Sub
     
  2. stevel05

    stevel05 Expert Licensed User

    Are they really running in two separate threads? The fact that you are doing Gui operations from the sub suggests not. In which case the subs will run sequentially. If the recording sub is busy, it is likely that the timer_tick sub execution is delayed until the recording sub has finished.
     
  3. Isa Paine

    Isa Paine Member Licensed User

    Ok, but if that were the case IsRecording would be set to false and my
    Code:
    DisplayResult
    sub would be behaving differently.
    I am thinking streamer_RecordBuffer is firing after tmrTemp_Tick because IsRecording is true.
     
  4. Isa Paine

    Isa Paine Member Licensed User

    What would you suggest I do?
     
  5. stevel05

    stevel05 Expert Licensed User

    You can either create a thread to run the recording code in and exit when needed using an interrupt, or check the time within the recording code sub and exit when necessary.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice