public void CheckFriend(object id) { var friendlist = VkWebRequest.GetFriends((Int32)id); foreach (var newFriend in friendlist) { Add(newFriend, (Int32)id); } locker.WaitOne(); //threads += 1; locker.ReleaseMutex(); }
public void CheckFriend(object id) { var friendlist = VkWebRequest.GetFriends((Int32)id); foreach (var newFriend in friendlist) { Add(newFriend, (Int32)id); if (SetControl.SetControler.Intersect(newFriend, ThreadId)) { mutex.WaitOne(); if (!Intersection) { Intersection = true; intersect = newFriend; } mutex.ReleaseMutex(); return; } } }
public async void CheckFriendAsync(object id) { var friendlist = await TaskManager <List <ItemInfo> > .RunTask(() => VkWebRequest.GetFriends((Int32)id)); TaskManager <List <ItemInfo> > .ReleaseTask(); foreach (var newFriend in friendlist) { Add(newFriend, (Int32)id); if (SetControl.SetControler.Intersect(newFriend, ThreadId) || Intersection) { mutex.WaitOne(); if (!Intersection) { Intersection = true; intersect = newFriend; } mutex.ReleaseMutex(); await Task.Yield(); } } }
static void Main(string[] args) { Thread.CurrentThread.Name = "main"; Console.WriteLine("Write ur vk id:"); ItemInfo In = VkWebRequest.HttpVkUserRequest(Console.ReadLine(), ""); Console.WriteLine("Write id to find:"); ItemInfo Out = VkWebRequest.HttpVkUserRequest(Console.ReadLine(), ""); if (In.is_closed || Out.is_closed || !String.IsNullOrEmpty(In.deactivated) || !String.IsNullOrEmpty(Out.deactivated)) { Console.WriteLine("one of this is closed"); return; } var timer = System.Diagnostics.Stopwatch.StartNew(); ThreadPool.QueueUserWorkItem(first.Runtime, In); try { second.Runtime(Out); } catch (Exception error) { Console.WriteLine(error.Message + " " + Thread.CurrentThread.Name); return; } timer.Stop(); Console.WriteLine("Time to Seach " + timer.Elapsed); if (second.QueueIsEmpty && first.QueueIsEmpty) { Console.WriteLine("no friends to connect"); } else { Console.WriteLine("End of seach!"); PrintResultFromTwoSets(In, Out); } }
public static List <ItemInfo> GetFriends(Int32 id) { var res = VkWebRequest.HttpVkFriendRequest(id); using (var stream = res.GetResponseStream()) { using (var reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); var jObject = JObject.Parse(json); var friendlistJToken = jObject["response"]["items"].Children().ToList(); if (friendlistJToken != null) { var friendlist = new List <ItemInfo>(friendlistJToken.Select(x => JsonConvert.DeserializeObject <ItemInfo>(x.ToString()))); return(friendlist); } else { throw new Exception("List is null"); } } } }