Tar*_*rik 0 c# process splash-screen
我想知道如何Loading Time在用户启动流程,应用程序实例时测量应用程序,以便我可以显示进度条或某些内容,通知用户在加载应用程序时发生了什么或者完成了多少应用程序加载.
我的意思是如果我想显示进度条的当前进度,所以我认为我能够用数字定义当前进程,所以我可以增加控件的Value属性ProgressBar.
提前致谢.
真诚.
编辑:
我发现的解决方案是:
您可以使用System.Diagnostics.Stopwatch来测量时间.调用方法Start在表单构造函数的开头.
显示表单后,通常Application.Idle事件会上升.因此,您可以在此事件的处理程序中调用Stop方法.但是你应该检查一下这个事件确实会上升,例如使用System.Diagnostics.Debug.WriteLine,以及来自sysinternals.com的工具DebugView.
所以我们可以System.Diagnostics.StopWatch像这样使用:
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine(elapsedTime, "RunTime");
}
}
Run Code Online (Sandbox Code Playgroud)
然后当空闲事件触发时,我将能够找到加载时间并在进度条上显示它,但我认为进度条不会显示加载时间的准确百分比.
您的进度条不太可能真实地显示剩余时间.一种常见的方法是使用完成加载的"步骤"数量.
假设您必须运行3个方法,每个方法还有2个子方法.这使它成为6.使用6步进度条.如果您基于试验错误,请确定哪个"步骤"可能需要更长时间,并为其分配更多"步数"
| 归档时间: |
|
| 查看次数: |
2734 次 |
| 最近记录: |