【发布时间】:2021-08-24 12:58:55
【问题描述】:
我想通过调用 DLL 中的方法从 Csharp 异步读取串行端口。请看下面的简单代码。
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
【问题讨论】:
标签: c# c++ asynchronous dll