Windows服务无法启动

时间:2017-06-07 10:46:26

标签: c# installation windows-services

我使用c#创建Windows服务但是在安装之后它不起作用 它在日志中没有显示任何内容,所以我不理解解决它的错误 。Error which is appeared

这是我的开始活动

     protected override void OnStart(string[] args)
        {
            StartSynchro();
        }
        public void StartSynchro()
        {
            while (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
              System.Threading.Thread.Sleep(TimeSpan.FromHours(1));

            }
            GoogleDriveHandler driveHandler = new GoogleDriveHandler();
            List<Google.Apis.Drive.v3.Data.File> onlineFiles = driveHandler.getFiles();
            Google.Apis.Drive.v3.Data.File onlineVerCSVFile = onlineFiles.Where(c => c.Name == GoogleDriveHandler.onlineVerCSV).First();
            onlineFiles.Remove(onlineVerCSVFile);
            List<KeyValuePair<string, string>> result = Helper.ReadFromMemoryStream(driveHandler.downloadfile_GetStream(ref onlineVerCSVFile));
            List<string> corspondingVer = new List<string>();
            foreach (var onlineFile in onlineFiles)
            {
                corspondingVer.Add(result.Find(c => c.Key == onlineFile.Name).Value);
            }

            List<Google.Apis.Drive.v3.Data.File> fileToDownload = LocalClasses.LocalFilesInfo.getFilesToDwonload(onlineFiles, corspondingVer, ref driveHandler);
            driveHandler.StartDownloading(fileToDownload);
            return;
        }

1 个答案:

答案 0 :(得分:1)

最好尽快启动Windows服务。您可以将初始化代码移动到单独的线程,如下所示:

protected override void OnStart(string[] args)
{
   Task.Run(() => StartSynchro());
}