public static void postfeedGroup(string fbaccesstoken, string fbgrpids, string feedid, string facebookaccountid,int time,Guid Id) { List<string> lstPost = new List<string>(); int lstCout = 0; bool isPosted = false; ShareathonGroupRepository shareagrp = new ShareathonGroupRepository(); Domain.Socioboard.Domain.SharethonGroupPost objshrgrp = new Domain.Socioboard.Domain.SharethonGroupPost(); FacebookClient fb = new FacebookClient(); string[] postid = feedid.TrimEnd(',').Split(','); fb.AccessToken = fbaccesstoken; Random r = new Random(); int length = postid.Length; while (length >= lstCout) { int i = r.Next(0, length - 1); if (!lstPost.Contains(postid[i])) { lstPost.Add(postid[i]); lstCout++; string[] group = fbgrpids.Split(','); foreach (var item in group) { string [] grpinfo = Regex.Split(item, "###"); isPosted = shareagrp.IsPostExist(grpinfo[0], postid[i], facebookaccountid); if (!isPosted) { string link = "https://www.facebook.com/" + postid[i]; var args = new Dictionary<string, object>(); args["link"] = link; try { if (shareagrp.IsShareathonExistById(Id)) { dynamic output = fb.Post("v2.0/" + grpinfo[0] + "/feed", args); objshrgrp.Id = Guid.NewGuid(); objshrgrp.Facebookaccountid = facebookaccountid; objshrgrp.Facebookgroupid = grpinfo[0]; objshrgrp.PostId = postid[i]; objshrgrp.PostedTime = DateTime.UtcNow; objshrgrp.Facebookgroupname = grpinfo[1]; shareagrp.AddShareathonPost(objshrgrp); } } catch (Exception ex) { Console.Write(ex.StackTrace); } Thread.Sleep(1000 * 30); } } Thread.Sleep(1000 *60*time); } } }