看板 C_Sharp 關於我們 聯絡資訊
目前用 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
yeo1987: delegate(C#)->function pointer(C)的方式處理進度? 03/20 23:56
我嘗試在 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
yeo1987: 你是想抓C# call C時Output的字串? 私心不建議這樣的模式 03/21 20:57
Litfal: 你是想抓自己程式link的C++ DLL的StdOut? 03/22 00:32
Litfal: 試試看用 SetStdHandle API 把-11或-12導到C#的PipeStream 03/22 00:40
disabledman: 怎不把流程控制放在上層 04/12 18:30