C# Files older than 20 days -> delete it automatically

Markus Freitag 3,786 Reputation points
2021-01-15T13:30:10.627+00:00

Hello,

I have a work folder and a folder "IsDone".
C:\Share\Work\
C:\Share\IsDone\

I need to delete files there without asking that are older than 20 days. How can I do this without blocking the application?

I need one thread, one task, Factory/parallel.
When I close the application, how do I stop this process?
Do you have an example with please?

Thanks!

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,281 questions
0 comments No comments
{count} votes

Accepted answer
  1. Markus Freitag 3,786 Reputation points
    2021-01-16T16:51:51.723+00:00

    OK, thanks, looks good!
    Question answered. Thank you very much.

    Last questions for understanding.

    I could also do this with TASK? Which do you think would be better? Can you compare the two?
    What are the advantages of TASK over Background Thread?

    When should i take what?


1 additional answer

Sort by: Most helpful
  1. Castorix31 81,826 Reputation points
    2021-01-15T14:37:15.457+00:00

    You can do something like this (change Sleep , Beep, LastAccessTime or LastWriteTime that I used for test...) =>

    I cannot post code, so a link = Test Thread delete files

    1 person found this answer helpful.