Managed DirectX Programming

I am starting to get up to speed with what I have to do to get sound sampled. The only problem is that now I am getting an error message – “Exception Details: System.InvalidOperationException: The operation is not valid due to the current state of the object.”

I have not yet been able to work out what is happening. The code at the moment is

Private Sub WaitThread()

Dim capturePos As Integer

Dim readPos As Integer

Dim buf(Notifysize) As Int16

While threadon = True

NotificationEvent.WaitOne(Timeout.Infinite, True)

capturebuffer.GetCurrentPosition(capturePos, readPos)

buf = capturebuffer.Read(readPos, buf.GetType, LockFlag.None, Notifysize)

Debug.WriteLine(Now)

End While

End Sub

Not all I need to do is find out why it is not working.