我在windows service中写了一句这样的代码,启动.exe
System.Diagnostics.Process.Start(Application.StartupPath + "\\windy.exe");在程序调试的时候,一切都OK。
但是在做成安装包后,安装以后,会出现这样的情况:
在进程管理中windy.exe启动起来了,也出现了winForm,但是我用先程做的一个倒计时label,却无法显示时间,但是如果在label.text中输入一个常量是可以显示的,请问我该怎么样解决这个问题,谢谢!~

解决方案 »

  1.   

    这是windy.exe中的代码:
    public frCountDown()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    this.threadStart = new System.Threading.ThreadStart(Application_Tick);
    this.thread = new System.Threading.Thread(threadStart);
    this.thread.Priority = System.Threading.ThreadPriority.Lowest;
    }private void frCountDown_Load(object sender, System.EventArgs e)
    {
    this.thread.Start();
    } public void Application_Tick()
    {
    this.lblNow.Text = "1111";
    string strXMLFilePath = string.Empty;
    iCareEye.iCareEyeClassLibrary.OperateXML operatexml = new iCareEye.iCareEyeClassLibrary.OperateXML();
    iCareEye.iCareEyeClassLibrary.OperateTime time = new iCareEye.iCareEyeClassLibrary.OperateTime();// strXMLFilePath = "F:" + "\\TaskTime.xml";
    strXMLFilePath = System.IO.Directory.GetCurrentDirectory() + "\\TaskTime.xml"; operatexml.LoadXML(strXMLFilePath);
    string strTaskTime = operatexml.ReadXML("nextintervaltime") + ":00";
    string strNowTime = System.DateTime.Now.ToLongTimeString();
    while(!strNowTime.Equals(strTaskTime))
    {
    this.lblNow.Text = time.MinusSecond(strTaskTime, strNowTime);
    System.Threading.Thread.Sleep(1000);
    strNowTime = System.DateTime.Now.ToLongTimeString();
    }
    this.Hide(); frScreenSaver frss = new frScreenSaver();
    frss.ShowDialog();

    this.Close();
    }
      

  2.   

    我建议楼主用MessageBox.Show看一下strNowTime和strTaskTime,看看这两个变量的值
      

  3.   

    建议搂住多看一些多线程编程的内容,另外,出了主线程,其他线程在访问GUI的控件的时候,最好用委托,否则会出现界面堵塞的问题。
      

  4.   

    线程开启的地方不要放到load里面做
      

  5.   

    好的,谢谢大家!~那请问线程的开启不放在load里面,应该放在哪?
      

  6.   

    不能在main()里加
    我是这样加的:
    static void Main() 
    {
    frCountDown fr = new frCountDown();
    fr.thread.Start();
    Application.Run(new frCountDown());
    }
    但是时间还是没有显示出来,另外会产生多个进程,并且在main函数里不能用this.thread.start();因为还没有实例化!~
      

  7.   

    我以前也遇到这类的问题,放到load中是不可能的,因为在load的时候,窗体上的控件并没有完全初始化,所以在对窗体上的控件操作的时候,有时候是达不到所想要的效果,当时我解决此类问题的时候,也没有找到比较好的办法,以下给出的方法不是太好,但是基本上能满足你所需要的
    1、在窗体上加一个timer,interval设为30就可以了,enable设为false;
    2、在窗体load事件最后,把上面的timer对象的enable设为true;
    3、然后在timer相应时间中,去启动线程,注意在此事件一开始的时候,要把timer的enable设为false。
      

  8.   

    终于知道是什么原因了,是因为
    strXMLFilePath = System.IO.Directory.GetCurrentDirectory() + "\\TaskTime.xml";
    不能用上面这句话,
    必须用strXMLFilePath = Application.StartupPath + "\\TaskTime.xml";如果是单独双击.exe文件是可以用System.IO.Directory.GetCurrentDirectory()这个的,但是要是有其它的.exe文件来启动另一个.exe文件时,要读当前目录必须用Application.StartupPath谢谢大家!^0^