0

我正在开发一个 Windows 窗体启动器/更新/启动屏幕应用程序,用于 C# 中的 Windows 7 Panasonic Toughbook(平板电脑)。启动器在我的桌面和我的一个 Toughbook 上运行良好......但是,在“真实环境”设备上进行测试需要 20 多秒才能在第一次启动后显示表单。(一旦显示表单,它就会快速运行,这是应用程序假定的工作方式。)安装后在设备上首次启动很快,但首次启动后需要很长时间。

我不确定如何进行测试,因为这是在无法通过 USB 连接或连接到我们的网络的设备上。应用程序是否打开文件似乎并不重要。事实上,在大多数情况下,应用程序只是打开,发现现在检查另一个更新还为时过早,启动主应用程序并杀死自己。

当前流程如下所示:

构造函数:

public MyConstructor() { InitializeComponent(); }

表单加载:

private void Form1_Load(object sender, EventArgs e)
{
    if (!isLoaded)
    {
        System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap("parentApplication.exe.config"); //Path to your config file
        System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
        log4net.Config.XmlConfigurator.Configure();
        WebRequest.url = configManager.AppSettings.Settings["SURL"].Value;

        // Set a timer to run the update process momentarily to allow the UI thread to update and display. (UI must be idle to run Timer)
        updateTimer = new System.Timers.Timer(1000);
        updateTimer.Elapsed += new ElapsedEventHandler(beginUpdate);
        updateTimer.Enabled = true;
        isLoaded = true;
    }
}

更新过程

private void beginUpdate(Object sender, EventArgs e)
{
    // If any of this fails, we still want to launch the main application. 
    try
    {
            // Prevent the timer from doing anything else.
            updateTimer.Enabled = false;

            string version = "0";
            try
            {
                Version v = AssemblyName.GetAssemblyName("ParentApplication.exe").Version;
                version = v.ToString();
            }
            catch
            {
                version = "0";
            }

            updateProgress(5);

            DateTime buffer = DateTime.Now.AddMinutes(-5);
            DateTime last = Convert.ToDateTime(configManager.AppSettings.Settings[lastCheck].Value);
            int comp = DateTime.Compare(buffer, last);

            if (comp < 0)
            {
                // Begin update process
                updateApplication(version);
            }

            updateProgress(100);

            System.Threading.Thread.Sleep(1000);
        }
        catch (Exception er)
        {
            logger.Error("Error in update application.", er);
        }

        // The updater can't update itself. Launch the external application
        // to handle the updating of the updater. This application also launches
        // the main executable.
        Process sync = new Process();
        sync.StartInfo.UseShellExecute = false;
        sync.StartInfo.FileName = "FinishUpdate.exe";
        sync.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        sync.StartInfo.Verb = "runas";
        sync.Start();
        Application.Exit();
}
4

1 回答 1

1

根据描述,分析器可能难以设置。另一种选择是运行StopWatch,它将方法执行时间记录到任意日志文件中。一旦您确定哪种方法性能不佳,您可以重复这些步骤,直到缩小导致瓶颈的代码行。

于 2013-04-30T16:50:11.070 回答