i used c# to create Windows service but after installing , it doesn't work and it shows nothing in log so i don't understand the error to solve it .
this is my on-start event
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;
}
It's better to start the windows service as fast as possible. You could move the initialization code to a separate thread as follows:
protected override void OnStart(string[] args)
{
Task.Run(() => StartSynchro());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.