mercredi 17 mai 2017

Returning Enum in async Task

I was looking to return an enum depending on the outcome of my asynchronous method.

public enum ReponseType
{
    Success,
    Error
}

Here is the method that returns the response type:

    public async Task<ReponseType> MethodThatDoesStuff()
    {
        await Task.Run(() =>
        {
            //Doing stuff here

            return ResponseType.Success;

        });
        return ReponseType.Error;
    }

when I call this method I can't get access to what the value is:

var resp = await _writer.MethodThatDoesStuff();

Even if I use:

ResponseType resp = await _writer.MethodThatDoesStuff();

I still can't get the enum value.

resp.[intellisense] only give me GetType(), GetTypeCode(), CompareTo() etc...

Is it not ok/efficient to return an enum like this if I only want to know if its a success or error?

What would be the best way to do this?

Thanks





Aucun commentaire:

Enregistrer un commentaire