c# - How to return a string from an async method? -


I want to return the string value to an async method. how can I do this? The method "getPlayerName" is now using async but the user of this method is expecting a string value.

  Public DataTable ToDataTable (list & lt; auction info & data; data) {property descriptor collection property = type descriptor GetProperties (typeform (auctioned information)); Datatyal table = new datatelle (); // loop propon = "player name" in all columns; Table Columns Add (Propanem, Propn. GateType ()); Foreach (prophylactic property properties) {table.Column.Add (prop.Name, Nullable.GetUnderlyingType (prop.PropertyType) ?? prop.PropertyType); } // todo All auction / advertenties add Columns PlayerName // Loop in foreach (Auction information auction in data) {DataRow row = table.NewRow (); Line ["player name"] = getPlayerName (auction information); // Loop in all the columns and set value foreach (support in property descriptor properties) {// column row set Val [Prong. Name] = propatititis (auction information) ?? DBNull.Value; } // add row to the data table. Rows. Add (line); } Return table; } Private async works & lt; String & gt; GetPlayerName (Auction insights auction information) {var items = wait for customer. Getitum ASCIN (Auction Info); String fullname = string Format ("{0} {1}", Item. First name, Item. Listname); Return full name; }    

You await for to use << Code> Tasks & lt; String & gt; :

  Wait for the string ["PlayerName"] string  = getPlayerNameAynync (Auction Info);  

This requires ToDataTable to become a async method, hence changing its name to ToDataTableAsync And it has been replaced by Tasks & lt; DataTable & gt; Revert.

Then callers of ToDataTable should use waiting and should be async methods async This growth is quite natural and should be embraced. In my, I describe it as "async all way".


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -