Suppose a folder is on some kind of network resource to which a low access speed.

If I just try to open methods of working with the file system through standard C #, the program will move.

You can put it in a separate Task, but in that case I still can’t use the cancellationtoken, because inside Task, when I call the file system function, I won’t be able to check it.

Is kokneretno correct in this case to abort the flow? It seems like they write everywhere that it is bad ...

  • Why can't you verify this? In a loop, you work asynchronously with file streams and check the token. | I recommend reading a small book (large article) Task-based Asynchronous Pattern (available officially free). At the end there is an example of asynchronous copying. - Alexander Petrov
  • @AlexanderPetrov, well, I called Directory.GetFiles on the ball, which is somewhere. How can I check any tokens if Directory.GetFiles is synchronous => I’m waiting and can’t perform checks on tokens. - Ricardo Milos
  • Opening (not copying) one file (or access to one folder) is also unacceptably long or normal? | Do not use GetFiles , use EnumerateFiles . - Alexander Petrov
  • @AlexanderPetrov even if you use EnumerateFiles, then you have any problems with the network or credentials, then the Windows 30 seconds knocking. But I just want to avoid this. If for 5 seconds I do not get what I want, I want to chop off. - Ricardo Milos

0