폴더 생성 태스크
while (true)
현재 요일 폴더 있는지 확인함
없으면 생성
현재 시간과 오늘 오후 11:59 시간 차이 계산
시간 차이만큼 sleep
폴더 제거 태스크
while (true)
설정된 시간 (한 달)보다 더 오래된 폴더 제거
현재 시간과 다음 날 0:00 시간 차이 계산
시간 차이만큼 sleep
try
{
string firstHttpFolderPath = "." + "/" + DateTime.Now.ToString("yyyyMMdd");
DirectoryInfo firstDi = new DirectoryInfo(firstHttpFolderPath);
if (firstDi.Exists == false)
{
firstDi.Create();
}
Task.Factory.StartNew(() =>
{
while (true)
{
string httpFolderPath = "." + "/" + DateTime.Now.AddDays(1).ToString("yyyyMMdd");
DirectoryInfo di = new DirectoryInfo(httpFolderPath);
if (di.Exists == false)
{
di.Create();
}
string currentTime = DateTime.Now.ToString("HHmmss");
DateTime compareTime = DateTime.Now.AddDays(1).Date.AddMinutes(-1);
int sleepTime = Convert.ToInt32((compareTime - DateTime.Now).TotalSeconds);
Thread.Sleep(sleepTime);
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
string httpFolderPath = ".";
DirectoryInfo di = new DirectoryInfo(httpFolderPath);
DateTime deleteDate = DateTime.Now.AddMonths(-1);
var folder = di.GetDirectories(httpFolderPath);
foreach (var folderName in folder)
{
DateTime compareName = DateTime.ParseExact(folderName.Name, "yyyyMMdd", provider);
if (compareName < deleteDate)
folderName.Delete();
}
string currentTime = DateTime.Now.ToString("HHmmss");
DateTime nextDay = DateTime.Now.AddDays(1).Date;
nextDay.AddDays(1);
int sleepTime = Convert.ToInt32((nextDay - DateTime.Now).TotalSeconds);
//Thread.Sleep(sleepTime);
}
});
}
catch (Exception ex)
{
log.Error(ex.Message);
}
'C# > c#' 카테고리의 다른 글
[ c# ] mysql bulk insert (0) | 2023.01.01 |
---|---|
[ c# ] mysql db 조회시 페이징 이용 (너무 많은 데이터 받아와야할때 사용) (0) | 2022.12.30 |
[ c# ] EF Core vs Dapper vs MySqlConnecter 성능 비교 (0) | 2022.12.27 |
[ c# ] MySqlConnector 로 mysql select , insert (0) | 2022.12.26 |
[ c# ] Dapper 사용해서 mysql select , insert (0) | 2022.12.24 |