【发布时间】:2016-02-04 22:45:55
【问题描述】:
如何解析实时 cmd 输出并在文本框中显示。示例
wkhtmltopdf http://www.google.com output.pdf
在 cmd 中给出以下内容
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[=============> ] 23%
[==================> ] 30%
[==============================> ] 51%
[=================================> ] 56%
[==================================> ] 58%
[========================================> ] 68%
[===============================================> ] 79%
[================================================> ] 81%
[==================================================> ] 84%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[============================================================] Page 1 of 1
Done
我想解析上面的内容并在一个文本框中的步骤(加载、计数 ....)中显示进度,在 () 中使用数字,在另一个文本框中使用数字,在另一个文本框中显示页数。
我尝试根据我的需要修改来自 How to parse command line output from c#? 的答案,但它无法成功。然后我在某个需要使用 BackgroundWorker 的地方阅读并尝试修改和使用来自http://www.codeproject.com/Articles/99143/BackgroundWorker-Class-Sample-for-Beginners 的代码但失败了。
【问题讨论】:
-
“修改”的方式是什么? “不能成功”有什么问题? “失败”并显示什么错误消息?
-
GUI 挂起。不知道如何应用 BackgroundWorker。
标签: c# visual-studio