Suppose in the depths of the program, there is a method:
public static string WriteSomeMethod(string Somedata){ //Бурная долгая деятельность return SomeData2; //Имитация возвращения данных } At the same time, we want our program not to hang when calling this method, so we write another one:
public static async Task<string> WriteSome(string Somedata){ return await Task.Run(()=> WriteSomeMethod(Somedata)); } If we try to call var tmpdata = WriteSome("123"); somewhere in another code var tmpdata = WriteSome("123"); then we see that var is not really a string , but Task<string> . To get a string, we need to do this: var tmpdata = await WriteSome("123"); and make this method asynchronous.
Making it asynchronous, you will need to make the result of its work Task, => you need to repeat it until the moment when we rest on the event handler and make it asynchronous. How to avoid this, and just return a string from WriteSome right away?
PS Sometimes there will be not a string, but a class, with a ton of variables.
return Task.Run(() => WriteSomeMethod(Somedata)).GetAwaiter().GetResult();- Bulson pmмы хотим, что бы наша программа не вешалась при вызове этого метода- tym32167 pmasync void. - John