[問題] C# 調用 C++ dll 的迴圈內資料
目前用 C++ 寫一個供 C# wpf UI 調用的 API
假設某個 C++ 的 loop 中
要每次都回傳某個資料(數值或字串等)出來給 C# 即時使用
(例如 更新 progress bar 或 show 進度的字串)
會有哪些建議的做法呢?
Console.OpenStandardInput 配合 backgroundworker? Task?
或是 其他較適合 MVVM 架構的做法?
感謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.42.50.191
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1490019188.A.B0C.html
推
03/20 23:56, , 1F
03/20 23:56, 1F
我嘗試在 c++ loop 中
cout 出來
並使用
Task.Run(
() =>
{
Process p = Process.GetCurrentProcess();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
while (true)
{
StreamReader sr = p.StandardOutput;
string strconsole = sr.ReadLine();
if (strconsole.Equals("Done"))
break;
}
});
不過 StandardOutput 卻出現錯誤
於 System.InvalidOperationException 擲回例外狀況: 'System.dll'
'System.InvalidOperationException' 類型的例外狀況發生於 System.dll,但使用者程
式碼未加以處理
其他資訊: StandardOut 尚未重新導向,或者處理序尚未啟動。
無法這樣使用嗎?
※ 編輯: b26168 (220.128.199.139), 03/21/2017 10:28:32
→
03/21 20:57, , 2F
03/21 20:57, 2F
→
03/22 00:32, , 3F
03/22 00:32, 3F
→
03/22 00:40, , 4F
03/22 00:40, 4F
→
04/12 18:30, , 5F
04/12 18:30, 5F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章
11
21
11
17