Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以中止/取消FileStream.Beginread异步读取操作_C#_.net_Asynchronous_Filestream_Beginread - Fatal编程技术网

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

C# 是否可以中止/取消FileStream.Beginread异步读取操作,c#,.net,asynchronous,filestream,beginread,C#,.net,Asynchronous,Filestream,Beginread,我想用USB接口控制STM32微控制器。Jan Axelson()创建了一些应用程序来展示USB HID类的用法,该类现在是我的基本源代码 为了检查我的设备是否有一些挂起的数据,我创建了一个线程,调用Filestream.BeginRead()例程。现在我想中止/取消这个请求,因为它在退出该线程后仍然处于打开/阻止状态(设置一个变量以取消线程循环)。所以我想知道如何执行这个BeginRead()调用的取消。或者,您对如何检查USB设备的连续发送数据有更好的了解吗 // USB read data

我想用USB接口控制STM32微控制器。Jan Axelson()创建了一些应用程序来展示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);
    }
}

您尝试过简单地处理流吗?是的,但是检查IAsyncResult ar.IsComplete返回false无效。我必须调用thread.abort来取消循环-(