在构造函数中起一个线程,MainThread是类的属性。
public MoniterDataBases()
{
// 该调用是 Windows.Forms 组件设计器所必需的。
InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化
MainThread=new Thread(new ThreadStart(ThreadFunc));
   MainThread.Priority=ThreadPriority.Normal;
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
MainThread.Start();
}public static void ThreadFunc()
   {
MessageBox.Show("ThreadFunc");
}
没反应,不弹出对话框。而且我即使注册启动服务后,在vs中也没法调试,它还说我没有注册服务或启动服务,但服务管理中的确已经started了。求助!!谢谢

解决方案 »

  1.   

    在OnStart里打印信息看看,打在系统应用程序日志里的哦,
    页面上放个eventLog控件,如下打印:eventLog1.WriteEntry("ok");
      

  2.   

    1.线程类
    2. windowFrom 类构造函数中写入相关信息,可以执行,不清楚兄弟问题所在1.
    using System;
    using System.Threading;namespace DownLoadFile
    {
    /// <summary>
    /// Summary description for Threaread.
    /// </summary>
    public class ThreareadDemo
    {
    public ThreareadDemo()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    private Thread mainThread;
    public Thread MainThread
    {
    get {return mainThread;}
    set {mainThread=value;}
     }

    }
    }

    2.
    public FrmQQMPLayer()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();
    ThreareadDemo demo=new ThreareadDemo();
    demo.MainThread=new System.Threading.Thread(new System.Threading.ThreadStart(this.StartThread));
    demo.MainThread.Priority=ThreadPriority.Normal;
    demo.MainThread.Start();
    }
    public void StartThread()
    {
    MessageBox.Show("启动");
    }