Is it possible to abort/cancel a FileStream.Beginread asynchronous read operation

1.2k views Asked by At

I want to control a STM32 microcontroller using the USB interface. Jan Axelson (http://www.lvr.com/hidpage.htm#MyExampleCode) has created some applications to show the usage of the USB HID class which is now my base source.

To check if my device has some pending data I have created a thread calling the Filestream.BeginRead() routine. Now I want to abort/cancel this request, because it is still open/blocked after exiting that thread (setting a variable to cancel the thread loop). So I am wondering how to perform a cancellation this BeginRead() call. Or do you have a better idea how to check for continuous sent data of the USB device?

// USB read data from device thread
while (boRunThread)
{
    if (boStopThread)
    {
        // perform clean-up, cancel BeginRead
        // ... Abort(ar)???
    }
    if (botransfer == false)
    {
        botransfer = true;  // Signal pending transfer
        ar = fileStreamDeviceData.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, callb, inputReportBuffer);
    }
}
0

There are 0 answers