I created a windows service in which the code will execute every 1 seconds
My code
if (Process.GetProcessesByName("my_process").Length > 0)
{
writelog("Started uploading files");
upload_file();
writelog("Finished uploading files");
}
I am checking whether the process is already running using GetProcessByName
.
It is not working because after every 1 second the the log file is getting an entry Started uploading files
So my log file will be
Started uploading files
Started uploading files
Started uploading files
Finished uploading files
Finished uploading files
Finished uploading files
What I need is
Started uploading files
Finished uploading files
Started uploading files
Finished uploading files
Started uploading files
Finished uploading files
ie. with out finishing the first cycle the service should not enter the process. Is there a way to achieve this