I have an abstract class FilesManager
which manages some files.
The methods are marked as Task<>
because i might be saving / reading the files to a cloud server via http request
, so i want to mark them as asynchronous
.
However, for now, i save the files on local disk, synchronusly
.
Is ok to return empty Task
in order to fix the error?
For example:
return Task.Factory.StartNew(() => { return; });
The below implementation of LocalDiskFilesManager
throws exception, because each method is expected to return a Task<>
object.
public abstract class FilesManager
{
public abstract Task SaveFileAsync(XDocument xDocument);
public abstract Task<XDocument> GetFileAsync(Guid file_Id);
}
// Synchronously
public class LocalDiskFilesManager : FilesManager
{
public override Task SaveFileAsync(XDocument xDocument)
{
string path = GetFilePath();
xDocument.Save(path);
// is ok to return an empty task? does it affects the performance / threads?
// return Task.Factory.StartNew(() => { return; });
}
public override Task<XDocument> GetFileAsync(Guid file_Id)
{
string path = GetFilePath(file_Id);
XDocument xDocument = XDocument.Load(path);
return xDocument;
// is ok to return an empty task? does it affects the performance / threads?
// return Task<XDocument>.Factory.StartNew(() => { return xDocument; });
}
}