c# 4.0 - Async calls in c# -
when execute code developed call async method of linq2twitter, getting system.aggregate exception, code below:
static async task<list<mytwitterstatus>> getretweets(ulong tweetid, twittercontext twitterctx) { list<mytwitterstatus> retweets = new list<mytwitterstatus>(); var publictweets = await (from tweet in twitterctx.status tweet.type == statustype.retweets && tweet.id == tweetid select tweet) .tolistasync(); if (publictweets != null) publictweets.foreach(tweet => { if (tweet != null && tweet.user != null) { mytwitterstatus tempstatus = new mytwitterstatus(); tempstatus.country = tweet.place.country; tempstatus.createdat = tweet.createdat; tempstatus.favoritecount = long.parse(tweet.favoritecount.tostring()); tempstatus.id = tweet.id; tempstatus.istruncated = tweet.truncated; tempstatus.lang = tweet.lang; tempstatus.maxid = tweet.maxid; tempstatus.placefullname = tweet.place.fullname; tempstatus.retweetcount = tweet.retweetcount; tempstatus.screenname = tweet.screenname; tempstatus.text = tweet.text; tempstatus.userfriends = tweet.user.friendscount; tempstatus.usercreated = tweet.user.createdat; tempstatus.userfollowers = tweet.user.followerscount; tempstatus.userfavorities = tweet.user.favoritescount; tempstatus.userfriends = tweet.user.friendscount; tempstatus.userlocation = tweet.user.location; tempstatus.username = tweet.user.name; tempstatus.usertweetcount = tweet.user.statusescount; retweets.add(tempstatus); } }); return retweets; }
the issue when called method
var authorizer = new singleuserauthorizer { credentialstore = new inmemorycredentialstore { consumerkey = sm.default.consumer_key2.tostring(), consumersecret = sm.default.consumer_secret2.tostring(), oauthtoken = sm.default.access_token2.tostring(), oauthtokensecret = sm.default.access_secret2.tostring() } }; twittercontext twitterctx = new twittercontext(authorizer); task<list<mytwitterstatus>> task = task<list<mytwitterstatus>>.factory.startnew(() => getretweets(ulong.parse(tweet.stringid), twitterctx).result); task.wait(); list<mytwitterstatus> templist = task.result.tolist<mytwitterstatus>(); foreach (var ret in templist) { un = file.removespecialcharacters(ret.username); sn = file.removespecialcharacters(ret.screenname); tweets.appendline(account + "," + getwe(ret.createdat) + "," + text + "," + un + "," + sn + "," + ret.createdat + "," + file.removespecialcharacters(ret.userlocation) + ",,,1,," + ret.usertweetcount + "," + ret.retweetcount + "," + ret.favoritecount + "," + ret.userfollowers);
i appreciate kind of assistance it, have no idea how solve it.
can add try/catch see inner exception is.
try { //perform operation here } catch (aggregateexception aex) { //dive inner exception }
Comments
Post a Comment