是否可以中止/取消 FileStream.Beginread 异步读取操作

发布于 2024-12-20 01:15:32 字数 803 浏览 0 评论 0原文

我想使用 USB 接口控制 STM32 微控制器。简·阿克塞尔森 (http://www.lvr.com/hidpage.htm#MyExampleCode)创建了一些应用程序来展示 USB HID 类的用法,该类现在是我的基础源。

为了检查我的设备是否有一些待处理的数据,我创建了一个调用 Filestream.BeginRead() 例程的线程。现在我想中止/取消这个请求,因为退出该线程后它仍然是打开/阻塞的(设置一个变量来取消线程循环)。所以我想知道如何执行取消此 BeginRead() 调用。或者您有更好的想法如何检查USB设备连续发送的数据吗?

// 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);
    }
}

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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文