Skip to content

async Task method how to await #23

@znyet

Description

@znyet
public class Test
{
    public static async Task<string> Add(string name)
    {
        await Task.Delay(1000);
        return "hello" + name;
    }

    public static async Task<int> Count()
    {
        await Task.Delay(1000);
        return 1;
    }
}

 var type = typeof(Test);
object m1 = type.CallMethod("Add", "Job");
object m2 = type.CallMethod("Count");

how to await m1 and m2 ?

Task<string> task1 = m1 as Task<string>;
Task<int> task2 = m2 as Task<int>;
Although this can be done

but how to do like common..

object val = await m1 ?
object val2 = await m2 ?

because i need the object value...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions