【发布时间】:2011-03-24 20:14:13
【问题描述】:
我正在用 Python 重写一个 C# 控制台应用程序,我想移植一个我编写的不确定的基于控制台的进度条类。
我有使用文本创建确定进度条的示例,但我不确定如何创建不确定的进度条。我假设我需要某种线程。感谢您的帮助!
这是课程:
public class Progress {
String _status = "";
Thread t = null;
public Progress(String status) {
_status = status;
}
public Progress Start() {
t = new Thread(() => {
Console.Write(_status + " ");
while (true) {
Thread.Sleep(300);
Console.Write("\r" + _status + " ");
Thread.Sleep(300);
Console.Write("\r" + _status + " . ");
Thread.Sleep(300);
Console.Write("\r" + _status + " .. ");
Thread.Sleep(300);
Console.Write("\r" + _status + " ...");
}
});
t.Start();
return this;
}
public void Stop(Boolean appendLine = false) {
t.Abort();
Console.Write("\r" + _status + " ... ");
if (appendLine)
Console.WriteLine();
}
}
(P.S.随意参加进度课程)
【问题讨论】:
-
作为一般规则,您不应该中止线程。见stackoverflow.com/questions/1559255/…。
标签: c# python progress-bar