using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Collections;
namespace cloud_sync
{
public partial class cloud_sync : ServiceBase
{
public cloud_sync()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
while (true)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "C:\\ec2\\ec2.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = true;
proc.Start();
proc.WaitForExit();
string[] filePaths = Directory.GetFiles(@"c:\My cloud\VM Instances\");
foreach (string filePath in filePaths)
File.Delete(filePath);
try
{
StreamReader sr = new StreamReader("c:/ec2/temp.txt");
if (new FileInfo("c:/ec2/temp.txt").Length > 0)
{
string line, temp, temp1;
string[] content = new string[4];
line = GetWord(sr);
line = GetWord(sr);
string[] terms = line.ToLower().Trim().Split('\t');
Console.WriteLine(terms[1]);
Console.WriteLine(terms[5]);
Console.WriteLine(terms[9]);
temp1 = terms[1];
content[0] = "Instance_id :" + terms[1];
content[1] = "Status :" + terms[5];
content[2] = "Type :" + terms[9];
if (terms[5].Equals("terminated"))
{
line = GetWord(sr);
}
else
{
line = GetWord(sr);
line = GetWord(sr);
}
terms = line.ToLower().Trim().Split('\t');
Console.WriteLine(terms[4]);
content[3] = "Name :" + terms[4];
int i = terms[4].Length;
temp = "c:/My cloud/VM Instances/" + temp1 + " (" + terms[4] + ")";
temp = temp + ".cvm";
File.WriteAllLines(temp, content);
while ((line = GetWord(sr)) != null)
{
line = GetWord(sr);
terms = line.ToLower().Trim().Split('\t');
Console.WriteLine(terms[1]);
Console.WriteLine(terms[5]);
Console.WriteLine(terms[9]);
temp1 = terms[1];
content[0] = "Instance_id :" + terms[1];
content[1] = "Status :" + terms[5];
content[2] = "Type :" + terms[9];
if (terms[5].Equals("terminated"))
{
line = GetWord(sr);
}
else
{
line = GetWord(sr);
line = GetWord(sr);
}
terms = line.ToLower().Trim().Split('\t');
Console.WriteLine(terms[4]);
content[3] = "Name :" + terms[4];
i = terms[4].Length;
temp = "c:/My cloud/VM Instances/" + temp1 + " (" + terms[4] + ")";
temp = temp + ".cvm";
File.WriteAllLines(temp, content);
}
}
sr.Close();
sr.Dispose();
System.Threading.Thread.Sleep(50000);
File.Delete("c:/ec2/temp.txt");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
protected override void OnStop()
{
}
static string GetWord(StreamReader sr)
{
return sr.ReadLine();
}
}
}
このシステム サービスを作成しましたが、このサービスを開始すると、 「Windows はローカル コンピューター でcloud_sync サービスを開始できませんでした。エラー: 1053 サービスはタイムリーに開始および制御要求に応答しませんでした。」というエラーが表示されます。そのステータスは「開始中」になります。これの何が問題なのか教えてください。これは私の最初のシステム サービスです。これから私を助けてください