I have a foreach loop which iterates over a list of ViewModels which contains a property called Task.Id. How do I assign the newly created Task ID from a Linq select statement to the current loop item e.g.
foreach(var item in lstIcmpEcho)
{
Task<PingReply>[] icmpEchoResult = (from itemhost in lstIcmpEcho
select new Ping().SendPingAsync(itemhost.Host, _timeout, _buffer, _pingOptions)
//seeking solution too.. item.PingID = Task.Id
).ToArray();
};
dvLes
Member
83 Points
30 Posts
Task<PingReply> and LiNQ
Mar 23, 2012 12:05 PM|LINK
Hi,
I have a foreach loop which iterates over a list of ViewModels which contains a property called Task.Id. How do I assign the newly created Task ID from a Linq select statement to the current loop item e.g.
foreach(var item in lstIcmpEcho) { Task<PingReply>[] icmpEchoResult = (from itemhost in lstIcmpEcho select new Ping().SendPingAsync(itemhost.Host, _timeout, _buffer, _pingOptions) //seeking solution too.. item.PingID = Task.Id ).ToArray(); };Les
asyed4u
Participant
1307 Points
268 Posts
Re: Task<PingReply> and LiNQ
Mar 23, 2012 12:39 PM|LINK
hi,
this post may be useful .. u can refer from (TopicName) Advanced: Looking at the Entire Change List for the Transaction
http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx
http://forums.asp.net/t/1774819.aspx/1
ramankashyap
Member
178 Points
43 Posts
Re: Task<PingReply> and LiNQ
Mar 23, 2012 01:10 PM|LINK
I'm not sure, if you are looking for something like this:
lstIcmpEcho.Select(item => new Ping { PingID = item.Id });dvLes
Member
83 Points
30 Posts
Re: Task<PingReply> and LiNQ
Mar 23, 2012 04:17 PM|LINK
Thank you very much for the info. It was almost 100% what I was looking for :).
icmpEchoResult = lstIcmpEcho.Select(c=> { Task<PingReply> _echoReply = new Ping().SendPingAsync(c.Host, _timeout, _buffer, _pingOptions); c.TaskId = _echoReply.Id; return _echoReply; }).ToArray();