namespace ShiftConnect.UI
{
public partial class Mainform : Form
{
public Mainform()
{
//thread to show splash screen
Thread threadLoading = new Thread(new ThreadStart(splashscreen));
threadLoading.Name = "Splash UI";
threadLoading.Priority = ThreadPriority.Normal;//定义级别
threadLoading.IsBackground = true;//定义是否后台线程
threadLoading.Start();//启动线程
InitializeComponent();
}
/// <summary>
/// 窗口创建事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Mainform_Load(object sender, EventArgs e)
{
if (AccessHelp.conntrue() == false)
{
MessageBox.Show("数据库连接失败!\r\n请查看数据库是否存在或者连接字符串是否正确", "提示");
this.Close();
}
else
{
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取WheelChange信息......"; }));
Thread.Sleep(1000);
Form_load();//载入CO2和wheelchange信息
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取交接事项信息......"; }));
Thread.Sleep(1000);
ShiftconnRefush();//载入交接事项
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取B/L设备信息......"; }));
Thread.Sleep(1000);
equipinfor();//载入设备信息
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取设备菜单......"; }));
Thread.Sleep(1000);
EvelauteMenu();//为cmb_pcLine装载下拉菜单
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取CO2库存信息......"; }));
Thread.Sleep(1000);
co2load();//装载co2设备菜单
Thread.Sleep(3000);
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.Dispose(); }));
this.WindowState = FormWindowState.Normal;
}
}
/// <summary>
/// 定义splash screen
/// </summary>
public static void splashscreen()
{
SplashForm = new Login();
Application.Run(SplashForm);
} public static Login SplashForm
{
get;
set;
}如上面的代码:是winform窗口的一个splash screen
并且本机上调试已经通过了(win7)
splash screen也能够实时的显示载入进度
但是为什么把exe文件发给别的电脑(xp)
打开程序后,程序只是显示一下就会自动关闭呢
很纠结,求教
开始把线程现在Program里面也是同样的问题
把Splash写成Program里面的Public类 来实现也是同样的问题
在自己电脑上运行完全没有问题
但是拷贝的别的电脑上就直接一闪而过,
不知道为什么
以上为猜测,主要你还想听清你说的你的一闪而过,进去程序啦没有。
我没有引用任何第三方DLL,现在发现时程序在WIN7下可以正常运行,但是在XP上有时候会一闪而过,有的xp上就会报错,报程序无法启动,程序是基于.net 3.5的 所有尝试的电脑都已经安装.net 3.5
具体问题是这样子的
xp上启动程序
会显示splash screen的界面,但是信息不会更新
Thread threadLoading = new Thread(new ThreadStart(splashscreen));
threadLoading.Name = "Splash UI";
threadLoading.Priority = ThreadPriority.Normal;//定义级别
threadLoading.IsBackground = true;//定义是否后台线程
threadLoading.Start();//启动线程
//以上线程已经成功启动,但是以下没有启动就跳出程序或者报错了
InitializeComponent();
if (AccessHelp.conntrue() == false)
{
MessageBox.Show("数据库连接失败!\r\n请查看数据库是否存在或者连接字符串是否正确", "提示");
this.Close();
}
else
{
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取WheelChange信息......"; }));
Thread.Sleep(1000);
Form_load();//载入CO2和wheelchange信息
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取交接事项信息......"; }));
Thread.Sleep(1000);
ShiftconnRefush();//载入交接事项
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取B/L设备信息......"; }));
Thread.Sleep(1000);
equipinfor();//载入设备信息
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取设备菜单......"; }));
Thread.Sleep(1000);
EvelauteMenu();//为cmb_pcLine装载下拉菜单
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.lable1.Text = "正在读取CO2库存信息......"; }));
Thread.Sleep(1000);
co2load();//装载co2设备菜单
Thread.Sleep(3000);
SplashForm.Invoke(new MethodInvoker(delegate { SplashForm.Dispose(); }));
this.WindowState = FormWindowState.Normal;
}
这部分代码写成方法放在构造函数中运行后,xp成功启动程序,就此结贴