返回首页

我想使用C#的Windows索引服务启动/停止。怎么办呢?
启动服务后,我想创建目录和范围......

回答

评论会员:游客 时间:2012/02/06
安德烈Kraak:看看这个例子:imgsrc=]
农Santosh:开始
public static void StartService(string serviceName, int timeoutMilliseconds)

{

  ServiceController service = new ServiceController(serviceName);

  try

  {

    TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

 

    service.Start();

    service.WaitForStatus(ServiceControllerStatus.Running, timeout);

  }

  catch

  {

    // ...

  }

}

public static void StopService(string serviceName, int timeoutMilliseconds)

{

  ServiceController service = new ServiceController(serviceName);

  try

  {

    TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

 

    service.Stop();

    service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

  }

  catch

  {

    // ...

  }

}
评论会员:RaviRanjankr 时间:2012/02/06
private void button5_Click(object sender, EventArgs e)

     {

         TextWriter tw = new StreamWriter("gridviewcontent.doc");

 

         for (int x = 0; x < dgv1.Columns.Count; x++)

         {

             tw.Write(dgv1.Columns[x].HeaderText);

             if (x != dgv1.Columns.Count - 1)

             {

                 tw.Write(", ");

             }

 

         }

 

         tw.WriteLine();

 

         //writing the data

         for (int x = 0; x < dgv1.Rows.Count - 1; x++)

         {

             for (int y = 0; y < dgv1.Columns.Count; y++)

             {

                 tw.Write(dgv1.Rows[x].Cells[y].Value);

                 if (y != dgv1.Columns.Count - 1)

                 {

                     tw.Write(", ");

                 }

             }

             tw.WriteLine();

         }

         tw.Close();

     }