Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[FEATURE]-Refine FileIO Async methods

Open jtalborough opened this issue 3 years ago • 1 comments

Remove the event on the class. ReadDataFromFileASync should accept a callback and return a status.

jtalborough avatar Jun 09 '22 17:06 jtalborough

After digging in a bit it appears that the current pattern is acceptable and common, especially given the limitations on .NET 3.5.

See https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/implementing-the-event-based-asynchronous-pattern

Per the docs :

Define a MethodNameAsync method that:

  • Returns void.
  • Takes the same parameters as the MethodName method.
  • Accepts multiple invocations.

I think the change that should be made is the file name should be returned in the EventArgs. This will allow the caller to sort out which data is from which call, allowing for multiple invocations. I see no reason to have the method accept a callback and return status.

In the future with .NET 4+ we can support a Task-Based Asynchronous Pattern https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/task-based-asynchronous-pattern-tap

jtalborough avatar Jun 10 '22 18:06 jtalborough