C#- return IEnumerable on task async callIs it possible to “await yield return DoSomethingAsync()”Calling the base constructor in C#Returning IEnumerable<T> vs. IQueryable<T>Deserialize JSON into C# dynamic object?How would I run an async Task<T> method synchronously?How do I turn a C# object into a JSON string in .NET?HttpClient.GetAsync(…) never returns when using await/asyncasync/await - when to return a Task vs void?Using async/await for multiple tasksHow do I return the response from an asynchronous call?.NET async webservice call with a callback
Are there any examples of technologies have been lost over time?
Basic Questions on Wiener Filtering
When going by a train from Paris to Düsseldorf (Thalys), can I hop off in Köln and then hop on again?
How to change the font style (not the size but the style) of algorithimc package
Where to place an artificial gland in the human body?
Is this photo showing a woman posing in the nude before teenagers real?
How do I address my Catering staff subordinate seen eating from a chafing dish before the customers?
Is there a reason why I should not use the HaveIBeenPwned API to warn users about exposed passwords?
What to do when you reach a conclusion and find out later on that someone else already did?
Iterate over non-const variables in C++
What does "see" in "the Holy See" mean?
Decreasing star size
How to Create an Image for Cantor's *Diagonal Argument* with a Diagonal Oval
The Sword in the Stone
Terence Tao–type books in other fields?
At what rate does the volume (velocity) of a note decay?
Integral of the integral using NIntegrate
Can I make a matrix from just a parts of the cells?
How do campaign rallies gain candidates votes?
Is dd if=/dev/urandom of=/dev/mem safe?
Why are so many countries still in the Commonwealth?
Examples of simultaneous independent breakthroughs
AC contactor 1 pole or 2?
How to avoid unconsciously copying the style of my favorite writer?
C#- return IEnumerable on task async call
Is it possible to “await yield return DoSomethingAsync()”Calling the base constructor in C#Returning IEnumerable<T> vs. IQueryable<T>Deserialize JSON into C# dynamic object?How would I run an async Task<T> method synchronously?How do I turn a C# object into a JSON string in .NET?HttpClient.GetAsync(…) never returns when using await/asyncasync/await - when to return a Task vs void?Using async/await for multiple tasksHow do I return the response from an asynchronous call?.NET async webservice call with a callback
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the following code:
public class TardiisServiceAsync
private static TardiisServiceAsync instance;
public static TardiisServiceAsync Instance
//Singleton
get
if (instance == null)
instance = new TardiisServiceAsync();
return instance;
public const string CACHE_PREFIX_TARDIIS_SERVICE = "TardiisServiceAsync_";
public static Dictionary<string, Tuple<string, object>> clients = new Dictionary<string, Tuple<string, object>>();
public delegate Task<IEnumerable<object>> GetServiceList(object client, string connectionId, TardiisServiceParameters parameters = null);
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
//Returns IEnumerable<object> task
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
return (IEnumerable<object>)result;
public async Task<IdNameObject[]> GetDemographicGroupsAsync()
//This task is called from hight level class
Task<IdNameObject[]> cacheValue = null;
string cacheKey = CACHE_PREFIX_TARDIIS_SERVICE + Membership.GetUser().UserName + "GetDemographicGroupsAsync" + GetMarketCode();
if (ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY] != null && bool.Parse(ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY]))
if (HttpContext.Current.Cache[cacheKey] == null)
var taskResult = InitializeTardiisInstanceAndCallService(GetDemographicGroupsDelegateAsync);
var test = await taskResult;
cacheValue = (Task<IdNameObject[]>)HttpContext.Current.Cache[cacheKey];//This is not implemented yet
return await cacheValue;
public static Task<T> Convert<T>(T value)
return Task.FromResult<T>(value);
public static EnumHelper.EnumMarketCode GetMarketCode(EnumHelper.EnumMarketCode? marketCode = null)
//Returns market code
if (!marketCode.HasValue)
return (EnumHelper.EnumMarketCode.US);
else
return marketCode.Value;
private Task<IEnumerable<object>> InitializeTardiisInstanceAndCallService(GetServiceList getServiceList, TardiisServiceParameters parameters = null, EnumHelper.EnumMarketCode? marketCode = null, bool creatingConnectionsForAllCountries = false, string username = "")
//Get the instance and call the tardiis correct tardiis service depends on the market code
marketCode = GetMarketCode(marketCode);
MembershipUser membershipUser = Membership.GetUser();
string currentUsername = (membershipUser != null ? membershipUser.UserName : username);
string currentKey = currentUsername + "_" + marketCode;
if (clients.ContainsKey(currentKey))
try
//check if the connection is still active, or we should reconnect.
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
catch (Exception)
//At this point there is no connection, we need to open it.
object client = TardiisServiceFactory.GetService(marketCode.Value);
UserDTO userDTO = UserService.Instance.GetByUsername(currentUsername);
TardiisUserDTO tardiisUserDTO = UserService.Instance.GetTardiisUserByUserIdAndMarketCode(userDTO.ID, marketCode.Value.ToString());
if (tardiisUserDTO.TardiisUsername == null)
if (creatingConnectionsForAllCountries)
return null;
else
throw new TardiisLoginException("Please enter your credentials");
object user = TardiisServiceFactory.GetUser(marketCode.Value, tardiisUserDTO.TardiisUsername, tardiisUserDTO.TardiisPassword);
string connectionId;
try
connectionId = (string)client.GetType().GetMethod("InitConnection").Invoke(client, new object[] user );
catch (FaultException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
catch (TargetInvocationException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
clients[currentKey] = new Tuple<string, object>(connectionId, client);
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
private void AddToCache(string key, object value)
HttpContext.Current.Cache.Add(key, value, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
I am getting the following error message:
Unable to cast object of type 'System.Threading.Tasks.Task[System.Object] to type 'System.Collections.Generic.IEnumerable1[System.Object].
The result of the task is a TypedClass[]
.
How can I return as a Task<IEnumerable<object>>
on the call method.
This is a "copy" of a another class that have similar logic but in a synchronized way. The idea is change some methods
so they can be run synchronously.
Thank you!
c# asynchronous task
|
show 8 more comments
I have the following code:
public class TardiisServiceAsync
private static TardiisServiceAsync instance;
public static TardiisServiceAsync Instance
//Singleton
get
if (instance == null)
instance = new TardiisServiceAsync();
return instance;
public const string CACHE_PREFIX_TARDIIS_SERVICE = "TardiisServiceAsync_";
public static Dictionary<string, Tuple<string, object>> clients = new Dictionary<string, Tuple<string, object>>();
public delegate Task<IEnumerable<object>> GetServiceList(object client, string connectionId, TardiisServiceParameters parameters = null);
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
//Returns IEnumerable<object> task
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
return (IEnumerable<object>)result;
public async Task<IdNameObject[]> GetDemographicGroupsAsync()
//This task is called from hight level class
Task<IdNameObject[]> cacheValue = null;
string cacheKey = CACHE_PREFIX_TARDIIS_SERVICE + Membership.GetUser().UserName + "GetDemographicGroupsAsync" + GetMarketCode();
if (ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY] != null && bool.Parse(ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY]))
if (HttpContext.Current.Cache[cacheKey] == null)
var taskResult = InitializeTardiisInstanceAndCallService(GetDemographicGroupsDelegateAsync);
var test = await taskResult;
cacheValue = (Task<IdNameObject[]>)HttpContext.Current.Cache[cacheKey];//This is not implemented yet
return await cacheValue;
public static Task<T> Convert<T>(T value)
return Task.FromResult<T>(value);
public static EnumHelper.EnumMarketCode GetMarketCode(EnumHelper.EnumMarketCode? marketCode = null)
//Returns market code
if (!marketCode.HasValue)
return (EnumHelper.EnumMarketCode.US);
else
return marketCode.Value;
private Task<IEnumerable<object>> InitializeTardiisInstanceAndCallService(GetServiceList getServiceList, TardiisServiceParameters parameters = null, EnumHelper.EnumMarketCode? marketCode = null, bool creatingConnectionsForAllCountries = false, string username = "")
//Get the instance and call the tardiis correct tardiis service depends on the market code
marketCode = GetMarketCode(marketCode);
MembershipUser membershipUser = Membership.GetUser();
string currentUsername = (membershipUser != null ? membershipUser.UserName : username);
string currentKey = currentUsername + "_" + marketCode;
if (clients.ContainsKey(currentKey))
try
//check if the connection is still active, or we should reconnect.
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
catch (Exception)
//At this point there is no connection, we need to open it.
object client = TardiisServiceFactory.GetService(marketCode.Value);
UserDTO userDTO = UserService.Instance.GetByUsername(currentUsername);
TardiisUserDTO tardiisUserDTO = UserService.Instance.GetTardiisUserByUserIdAndMarketCode(userDTO.ID, marketCode.Value.ToString());
if (tardiisUserDTO.TardiisUsername == null)
if (creatingConnectionsForAllCountries)
return null;
else
throw new TardiisLoginException("Please enter your credentials");
object user = TardiisServiceFactory.GetUser(marketCode.Value, tardiisUserDTO.TardiisUsername, tardiisUserDTO.TardiisPassword);
string connectionId;
try
connectionId = (string)client.GetType().GetMethod("InitConnection").Invoke(client, new object[] user );
catch (FaultException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
catch (TargetInvocationException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
clients[currentKey] = new Tuple<string, object>(connectionId, client);
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
private void AddToCache(string key, object value)
HttpContext.Current.Cache.Add(key, value, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
I am getting the following error message:
Unable to cast object of type 'System.Threading.Tasks.Task[System.Object] to type 'System.Collections.Generic.IEnumerable1[System.Object].
The result of the task is a TypedClass[]
.
How can I return as a Task<IEnumerable<object>>
on the call method.
This is a "copy" of a another class that have similar logic but in a synchronized way. The idea is change some methods
so they can be run synchronously.
Thank you!
c# asynchronous task
1
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert theTask<MyCustomClass>
result toTask<IEnumerable<object>>
. Thank you.
– Marcelo Arias
Mar 26 at 17:54
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
The result isTask<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method:public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00
|
show 8 more comments
I have the following code:
public class TardiisServiceAsync
private static TardiisServiceAsync instance;
public static TardiisServiceAsync Instance
//Singleton
get
if (instance == null)
instance = new TardiisServiceAsync();
return instance;
public const string CACHE_PREFIX_TARDIIS_SERVICE = "TardiisServiceAsync_";
public static Dictionary<string, Tuple<string, object>> clients = new Dictionary<string, Tuple<string, object>>();
public delegate Task<IEnumerable<object>> GetServiceList(object client, string connectionId, TardiisServiceParameters parameters = null);
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
//Returns IEnumerable<object> task
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
return (IEnumerable<object>)result;
public async Task<IdNameObject[]> GetDemographicGroupsAsync()
//This task is called from hight level class
Task<IdNameObject[]> cacheValue = null;
string cacheKey = CACHE_PREFIX_TARDIIS_SERVICE + Membership.GetUser().UserName + "GetDemographicGroupsAsync" + GetMarketCode();
if (ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY] != null && bool.Parse(ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY]))
if (HttpContext.Current.Cache[cacheKey] == null)
var taskResult = InitializeTardiisInstanceAndCallService(GetDemographicGroupsDelegateAsync);
var test = await taskResult;
cacheValue = (Task<IdNameObject[]>)HttpContext.Current.Cache[cacheKey];//This is not implemented yet
return await cacheValue;
public static Task<T> Convert<T>(T value)
return Task.FromResult<T>(value);
public static EnumHelper.EnumMarketCode GetMarketCode(EnumHelper.EnumMarketCode? marketCode = null)
//Returns market code
if (!marketCode.HasValue)
return (EnumHelper.EnumMarketCode.US);
else
return marketCode.Value;
private Task<IEnumerable<object>> InitializeTardiisInstanceAndCallService(GetServiceList getServiceList, TardiisServiceParameters parameters = null, EnumHelper.EnumMarketCode? marketCode = null, bool creatingConnectionsForAllCountries = false, string username = "")
//Get the instance and call the tardiis correct tardiis service depends on the market code
marketCode = GetMarketCode(marketCode);
MembershipUser membershipUser = Membership.GetUser();
string currentUsername = (membershipUser != null ? membershipUser.UserName : username);
string currentKey = currentUsername + "_" + marketCode;
if (clients.ContainsKey(currentKey))
try
//check if the connection is still active, or we should reconnect.
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
catch (Exception)
//At this point there is no connection, we need to open it.
object client = TardiisServiceFactory.GetService(marketCode.Value);
UserDTO userDTO = UserService.Instance.GetByUsername(currentUsername);
TardiisUserDTO tardiisUserDTO = UserService.Instance.GetTardiisUserByUserIdAndMarketCode(userDTO.ID, marketCode.Value.ToString());
if (tardiisUserDTO.TardiisUsername == null)
if (creatingConnectionsForAllCountries)
return null;
else
throw new TardiisLoginException("Please enter your credentials");
object user = TardiisServiceFactory.GetUser(marketCode.Value, tardiisUserDTO.TardiisUsername, tardiisUserDTO.TardiisPassword);
string connectionId;
try
connectionId = (string)client.GetType().GetMethod("InitConnection").Invoke(client, new object[] user );
catch (FaultException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
catch (TargetInvocationException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
clients[currentKey] = new Tuple<string, object>(connectionId, client);
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
private void AddToCache(string key, object value)
HttpContext.Current.Cache.Add(key, value, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
I am getting the following error message:
Unable to cast object of type 'System.Threading.Tasks.Task[System.Object] to type 'System.Collections.Generic.IEnumerable1[System.Object].
The result of the task is a TypedClass[]
.
How can I return as a Task<IEnumerable<object>>
on the call method.
This is a "copy" of a another class that have similar logic but in a synchronized way. The idea is change some methods
so they can be run synchronously.
Thank you!
c# asynchronous task
I have the following code:
public class TardiisServiceAsync
private static TardiisServiceAsync instance;
public static TardiisServiceAsync Instance
//Singleton
get
if (instance == null)
instance = new TardiisServiceAsync();
return instance;
public const string CACHE_PREFIX_TARDIIS_SERVICE = "TardiisServiceAsync_";
public static Dictionary<string, Tuple<string, object>> clients = new Dictionary<string, Tuple<string, object>>();
public delegate Task<IEnumerable<object>> GetServiceList(object client, string connectionId, TardiisServiceParameters parameters = null);
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
//Returns IEnumerable<object> task
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
return (IEnumerable<object>)result;
public async Task<IdNameObject[]> GetDemographicGroupsAsync()
//This task is called from hight level class
Task<IdNameObject[]> cacheValue = null;
string cacheKey = CACHE_PREFIX_TARDIIS_SERVICE + Membership.GetUser().UserName + "GetDemographicGroupsAsync" + GetMarketCode();
if (ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY] != null && bool.Parse(ConfigurationManager.AppSettings[ConstantsHelper.FIELD_CONFIG_USE_CACHE_KEY]))
if (HttpContext.Current.Cache[cacheKey] == null)
var taskResult = InitializeTardiisInstanceAndCallService(GetDemographicGroupsDelegateAsync);
var test = await taskResult;
cacheValue = (Task<IdNameObject[]>)HttpContext.Current.Cache[cacheKey];//This is not implemented yet
return await cacheValue;
public static Task<T> Convert<T>(T value)
return Task.FromResult<T>(value);
public static EnumHelper.EnumMarketCode GetMarketCode(EnumHelper.EnumMarketCode? marketCode = null)
//Returns market code
if (!marketCode.HasValue)
return (EnumHelper.EnumMarketCode.US);
else
return marketCode.Value;
private Task<IEnumerable<object>> InitializeTardiisInstanceAndCallService(GetServiceList getServiceList, TardiisServiceParameters parameters = null, EnumHelper.EnumMarketCode? marketCode = null, bool creatingConnectionsForAllCountries = false, string username = "")
//Get the instance and call the tardiis correct tardiis service depends on the market code
marketCode = GetMarketCode(marketCode);
MembershipUser membershipUser = Membership.GetUser();
string currentUsername = (membershipUser != null ? membershipUser.UserName : username);
string currentKey = currentUsername + "_" + marketCode;
if (clients.ContainsKey(currentKey))
try
//check if the connection is still active, or we should reconnect.
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
catch (Exception)
//At this point there is no connection, we need to open it.
object client = TardiisServiceFactory.GetService(marketCode.Value);
UserDTO userDTO = UserService.Instance.GetByUsername(currentUsername);
TardiisUserDTO tardiisUserDTO = UserService.Instance.GetTardiisUserByUserIdAndMarketCode(userDTO.ID, marketCode.Value.ToString());
if (tardiisUserDTO.TardiisUsername == null)
if (creatingConnectionsForAllCountries)
return null;
else
throw new TardiisLoginException("Please enter your credentials");
object user = TardiisServiceFactory.GetUser(marketCode.Value, tardiisUserDTO.TardiisUsername, tardiisUserDTO.TardiisPassword);
string connectionId;
try
connectionId = (string)client.GetType().GetMethod("InitConnection").Invoke(client, new object[] user );
catch (FaultException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
catch (TargetInvocationException ex)
// This exception is catched globally by BaseController and prompts the user to enter his
// tardiis credentials again
throw new TardiisLoginException(ex.InnerException.Message, ex);
clients[currentKey] = new Tuple<string, object>(connectionId, client);
return getServiceList(clients[currentKey].Item2, clients[currentKey].Item1, parameters);
private void AddToCache(string key, object value)
HttpContext.Current.Cache.Add(key, value, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
I am getting the following error message:
Unable to cast object of type 'System.Threading.Tasks.Task[System.Object] to type 'System.Collections.Generic.IEnumerable1[System.Object].
The result of the task is a TypedClass[]
.
How can I return as a Task<IEnumerable<object>>
on the call method.
This is a "copy" of a another class that have similar logic but in a synchronized way. The idea is change some methods
so they can be run synchronously.
Thank you!
c# asynchronous task
c# asynchronous task
edited Mar 26 at 20:20
Marcelo Arias
asked Mar 26 at 17:41
Marcelo AriasMarcelo Arias
62 bronze badges
62 bronze badges
1
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert theTask<MyCustomClass>
result toTask<IEnumerable<object>>
. Thank you.
– Marcelo Arias
Mar 26 at 17:54
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
The result isTask<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method:public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00
|
show 8 more comments
1
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert theTask<MyCustomClass>
result toTask<IEnumerable<object>>
. Thank you.
– Marcelo Arias
Mar 26 at 17:54
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
The result isTask<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method:public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00
1
1
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert the
Task<MyCustomClass>
result to Task<IEnumerable<object>>
. Thank you.– Marcelo Arias
Mar 26 at 17:54
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert the
Task<MyCustomClass>
result to Task<IEnumerable<object>>
. Thank you.– Marcelo Arias
Mar 26 at 17:54
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
The result is
Task<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method: public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
The result is
Task<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method: public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00
|
show 8 more comments
2 Answers
2
active
oldest
votes
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
var resultado = test.Result;
return Convert(new List<Object>resultado);
add a comment |
If you have an IEnumerable<A>
like an array you can cast it to IEnumerable<object>
using the Linq-Methode Cast<object>()
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var task = await test;
var taskResult = await task;
return taskResult.Cast<object>();
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type oftest
and what the type oftask
is.
– Ackdari
Mar 27 at 21:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363273%2fc-return-ienumerableobject-on-task-async-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
var resultado = test.Result;
return Convert(new List<Object>resultado);
add a comment |
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
var resultado = test.Result;
return Convert(new List<Object>resultado);
add a comment |
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
var resultado = test.Result;
return Convert(new List<Object>resultado);
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var result = await test;
var resultado = test.Result;
return Convert(new List<Object>resultado);
edited Mar 26 at 18:00
answered Mar 26 at 17:44
PliskinPliskin
3324 silver badges15 bronze badges
3324 silver badges15 bronze badges
add a comment |
add a comment |
If you have an IEnumerable<A>
like an array you can cast it to IEnumerable<object>
using the Linq-Methode Cast<object>()
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var task = await test;
var taskResult = await task;
return taskResult.Cast<object>();
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type oftest
and what the type oftask
is.
– Ackdari
Mar 27 at 21:15
add a comment |
If you have an IEnumerable<A>
like an array you can cast it to IEnumerable<object>
using the Linq-Methode Cast<object>()
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var task = await test;
var taskResult = await task;
return taskResult.Cast<object>();
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type oftest
and what the type oftask
is.
– Ackdari
Mar 27 at 21:15
add a comment |
If you have an IEnumerable<A>
like an array you can cast it to IEnumerable<object>
using the Linq-Methode Cast<object>()
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var task = await test;
var taskResult = await task;
return taskResult.Cast<object>();
If you have an IEnumerable<A>
like an array you can cast it to IEnumerable<object>
using the Linq-Methode Cast<object>()
public async Task<IEnumerable<object>> GetDemographicGroupsDelegateAsync(object client, string connectionId, TardiisServiceParameters parameters = null)
var test = Convert(client.GetType().GetMethod("GetDemographicGroupsAsync").Invoke(client, new object[] connectionId ));
var task = await test;
var taskResult = await task;
return taskResult.Cast<object>();
answered Mar 26 at 19:12
AckdariAckdari
3411 silver badge10 bronze badges
3411 silver badge10 bronze badges
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type oftest
and what the type oftask
is.
– Ackdari
Mar 27 at 21:15
add a comment |
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type oftest
and what the type oftask
is.
– Ackdari
Mar 27 at 21:15
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
Hi Ackdari, thank you but the variable taskResullt is an object type, and is not awatiable, I am right?.
– Marcelo Arias
Mar 27 at 12:48
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type of
test
and what the type of task
is.– Ackdari
Mar 27 at 21:15
@MarceloArias well, I don't know what the types of your objects are? I may be abel to clarify my answer if you tell me what the type of
test
and what the type of task
is.– Ackdari
Mar 27 at 21:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363273%2fc-return-ienumerableobject-on-task-async-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
var taskResult = task.Result; this is not a task when you add .result it will be an enumerable or other type you use
– Pliskin
Mar 26 at 17:46
Hi @Pliskin, thank you for your response, I understand that, but I cannot convert the
Task<MyCustomClass>
result toTask<IEnumerable<object>>
. Thank you.– Marcelo Arias
Mar 26 at 17:54
what is the type of taskResult and the param type of convert method?
– Pliskin
Mar 26 at 17:56
The result is
Task<TardiisPlanning.TardiisPlanningService.DemographicGroup[]>
a custom class array. Below i leave the code of the Convert method:public static Task<T> Convert<T>(T value) return Task.FromResult<T>(value);
– Marcelo Arias
Mar 26 at 17:59
Check the updated code and let me know if it works, or add this as param of Convert resultado.ToList()
– Pliskin
Mar 26 at 18:00