public static void ThreadFunc()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(10 * 1000);
                WorkFlowWS.Service rws = new WorkFlowWS.Service();
                string msg = rws.GetReminder(108);
                if (msg != "")
                {
                     //打开一个窗体
                }
            }
        }这是一个Windows服务中的线程,我想在 msg != "" 时打开一个窗体,该如何实现呢,谢谢!

解决方案 »

  1.   

    psi = new ProcessStartInfo();
    psi.FileName = "SimpleCopy.exe";//注上你要打开的EXE名称
    Process p = new Process();
    p.StartInfo = psi;
    p.Start();试试它看行不行:)
      

  2.   

    是線程還是進程?
    是進程的話,就用樓上那位仁兄的方法。
    要是線程就用如下方法:
    先引用System.Windows.Forms
    using System.windows.Forms;
    if (msg != "")
    {
        Form  temp = new Form();
        MethodInvoke mi  = new MethodInvoke( temp.Show );
        this.Invoke( mi );
    }
      

  3.   

    Invoke方法..如果不传递参数,楼上的可行...
      

  4.   

    if (msg != "")
    {
        Form  temp = new Form();
        MethodInvoke mi  = new MethodInvoke( temp.Show );
        this.Invoke( mi );
    }
      

  5.   

    MethodInvoke 的命名空间是什么,我怎么找不到呢
      

  6.   

    就是一个委托,不用那个也行,自己定义一个:public delegate void MyInvoke();if (msg != "")
    {
        Form  temp = new Form();
        MyInvokemi  = new MyInvoke( temp.Show );
        this.BeginInvoke( mi );
    }
      

  7.   

    this.Invoke( mi ); 或 this.BeginInvoke( mi ); 我这怎么找不到呢?
      

  8.   

    我用的是Windows Service程序,他没有Invoke方法
      

  9.   


    ///调用的方法
    all_alose d = new all_alose(allClose);
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, d);        ///定义的委托
            delegate void all_alose();
            /// <summary>
            /// 窗体变换[实际工作的方法]
            /// </summary>
            void allClose()
            {
                AccessibilityClient ac = new AccessibilityClient();
                ac.Show();            this.Close();
            }
      

  10.   

    using System.Threading; public class ShowUserMessageForm 
    {
    delegate void ShowForm(); private UserMessageForm _userMessage;
    private MainForm _currentForm;
    public ShowUserMessageForm(MainForm currentForm,UserMessage userMessageForm)
    {
    this._currentForm = currentForm;
    this._userMessage = userMessage;
    }
    public void Show()
    {
    Thread t = new Thread(new ThreadStart(show));
    t.Start();
    }
    private void show()
    {
                           if(this.currentForm != null && _userMessage != null)
              this._currentForm.Invoke(new ShowForm(showForm));
    }
    private void showForm()
    {
                            userMessageForm.Show();
      }
    } 这样用:
    ShowUserMessageForm  sum = new ShowUserMessageForm (this, yourWantShowForm);
    sum.Show();
      

  11.   

    我是想知道在 Windows 服务 程序 中怎么打开一个窗体,我的程序里没有主窗体,就有一个要用程序打开的窗体!!!
      

  12.   

    private void showForm()
    {
                            userMessageForm.Show();
      }改一下,
    private void showForm()
    {
                            Application.Run(userMessageForm);
      }