启动画面等待线程完成 [英] Splash Screen waiting until thread finishes

查看:18
本文介绍了启动画面等待线程完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的启动画面仍然有问题.我不想使用属性 SC.TopMost=true.

I still have a problem with the splash screen. I don't want to use the property SC.TopMost=true.

现在我的应用场景如下:

Now my application scenario is as follows:

在 progeram.cs 中:

[STAThread]
static void Main()
{
    new SplashScreen(_tempAL);// where _tempAL is an arrayList
    Application.Run(new Form1(_tempAL));
}

在 SplashScreen 类中:

public SplashScreen(ArrayList _Data)
{
    DisplaySplash()
} 
private void DisplaySplash()
{
    this.Show();
    this.TopMost = true;
    this.CenterToScreen();
    this.SetTopLevel(true);

    _allServerNarrators = new string[10];
    for (int i = 0; i < _allServerNarrators.Length; i++)
        _allServerNarrators[i] = null;

    GetFromServer();

    this.Hide();
    _serverData = new ArrayList();
    _thisData.Add(_allServerNarrators);
    _thisData.Add(_serverNarrators);

}
private void GetFromServer()
{
    _serverNarrators = new ArrayList();
    string _file = "Suras.serverNar";

    if (!Directory.Exists("c:\ASGAQuraan"))
        Directory.CreateDirectory("c:\ASGAQuraan");

    while (counter < 4 && _serverFiles == null)
    {
        if (Download("c:\ASGAQuraan", _ftpServerIP, _file))
        {
            StreamReader _strReader = new StreamReader
                         ("c:\ASGAQuraan\"+_file,System.Text.Encoding.Default);
            string _line = _strReader.ReadLine();
            string _word;

            while (true)
            {
                while (_line != null)
                {
                    _word = _line.Substring(0, _line.IndexOf("*"));
                    int _narId = Convert.ToInt32(_word);
                    _line = _line.Substring(2);
                    int k = 0;
                    _serverNarratorNode = new ArrayList();
                    while (true)
                    {
                        int ind = _line.IndexOf("*");
                        if (ind > 0 && ind < _line.Length)
                        {
                            string str = _line.Substring(0, (ind));
                            if (k == 0)
                            {
                                _allServerNarrators[_narId] = str;
                                _serverNarratorNode.Add(str);
                            }
                            else
                            {
                                _serverNarratorNode.Add(str);
                            }
                            _line = _line.Substring(ind + 1);
                            k++;
                        }
                        else
                        {
                            _line = null;
                            break;
                        }
                    }
                    _serverNarrators.Add(_serverNarratorNode);
                    _serverFiles = "added";
                }
                _line = _strReader.ReadLine();
                if (_line == null)
                {
                    break;
                }
            }
        }
        else
            counter++;
    }
}

我想要的是在启动画面类中等待线程完成的东西.

What I want is something in the splash screen class which waits until the thread finishes.

欲了解更多详情,请告诉我我需要告诉你什么.

For more details, please tell me what I need to tell you.

推荐答案

关注 2 个线程有点令人困惑,但我要试一试说这个...

Following across 2 threads is a bit confusing, but I'm going to take a stab and say this...

我不完全理解你的设计,但如果问题是当你启动第二个应用程序时,启动画面会变成白色......这很可能是因为启动画面正忙于执行所有这些GetFromServer() 中的代码.忙到没时间自己重新粉刷.

I don't fully understand your design here, but if the issue is that when you launch a second application the splash screen form turns white... It's most likely due to the fact that splash screen is busy executing all of that code in GetFromServer(). So busy that it has no time to re-paint itself.

为了解决这个问题,我建议您使用 BackGroundWorker 组件 执行 GetFromServer 方法.这将在单独的线程中运行该方法,并使表单的线程可以自由地重新绘制自身.

To remedy this problem I would suggest that you use the BackGroundWorker component to execute the GetFromServer method. This will run that method in a separate thread and leave the form's thread free to re-paint itself.

这篇关于启动画面等待线程完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆