c# - CPP - Async 不适用于 DLL 和 C-Sharp
问题描述
我想通过调用 DLL 中的方法从 Csharp 异步读取串行端口。请通过下面的简单代码。
夏普项目:
[DllImport("SerialTry.dll")]
public static extern void connectDevice();
static void Main(string[] args) {
connectDevice();
Console.WriteLine("Printed after reading 50 bytes connectDevice() - WHY?");
}
DLL 项目:
void connectDevice(){
//Reads 50 Bytes and print byte number from serial port async
auto result = std::async(std::launch::async, &DeviceControlActivity::read_data, this, std::ref(my_serial));
cout << "Printing before reading 50 Bytes - EXPECTED!\n";
}
Output:
Printing before reading 50 Bytes - EXPECTED!
#1 #2 #3 .... #50
Printed after reading 50 bytes connectDevice() - WHY?
Expected:
Printing before reading 50 Bytes - EXPECTED!
Printed after reading 50 bytes connectDevice() - WHY?
#1 #2 #3 .... #50
解决方案
推荐阅读
- iot - 在 BigchainDB 中断言为 IOT
- c# - 三元运算符未给出预期结果
- c - 初始化时 C-LibCurl 崩溃:curl_global_init() 和 curl_easy_init()
- javascript - 用于阻止页面在新选项卡中打开的 HTML 代码
- ffmpeg - Ffmpeg 使用 cuvid 连接具有硬件加速的视频文件
- java - Rally API to retrieve corresponding test sets & test cases by applying query filter with Project ID & Iteration name?
- jenkins - How do Jenkins pipeline builds determine the workspace folder?
- python - Specifying Schema of CSV in Apache Spark
- logstash - 在 Logstash 过滤器中拥有多个 grok 模式的正确方法是什么?
- magento-1.9 - Magento 1.9 - 在订单历史页面中显示可配置的产品图片