I need to call the sync method in async for some process and return it as the async's method result, how to do that in c#?
my async method
public async Task<object> SendAsync([FromBody] JObject _jo) { .... .... int _i1 = Models.Test.CallSync1(); int _i2 = Models.Test.CallSync2(_i1); object _ret = new { result = true, msg = "", payload = new { data = _i2 } }; return await Task.FromResult(_ret); }
my sync method
public static int CallSync1() { return random.Next(5); } public static int CallSync2(int _i) { return _i * random.Next(5); }
https://stackoverflow.com/questions/66978263/how-to-call-sync-method-in-async-method-in-c April 07, 2021 at 08:55AM
没有评论:
发表评论