示例#1
0
        private Dictionary <int, Pingable> AssertAliveServers(IAsyncResult[] results, WaitHandle[] wait_handles, Pingable[] pingables)
        {
            Dictionary <int, Pingable> new_view = new Dictionary <int, Pingable>();

            for (int i = 0; i < Pingables.Count; i++)
            {
                if (wait_handles[i].WaitOne(0))
                {
                    AsyncPingDelegate del = (AsyncPingDelegate)((AsyncResult)results[i]).AsyncDelegate;
                    try
                    {
                        del.EndInvoke(results[i]);
                        new_view.Add(i, pingables[i]);
                    }
                    catch (Exception error)
                    {
                        //Do nothing, the server is really dead or is behaving badly.
                        //Console.WriteLine("VIEW MANAGER: A pingable is behaving weirdly, check it out");
                        //Console.WriteLine(error.ToString());
                    }
                }
                else
                {
                    //Console.WriteLine("Ups");
                    //Server is probably alive but he just timed out or is not currently responding
                    //Assume that it died, he will come back eventually if he really is alive.
                    //When you don't use EndInvoke you simply dont get the return value.
                }
            }
            return(new_view);
        }
示例#2
0
        private List <string> AssertAliveServers(Dictionary <string, KeyValuePair <IAsyncResult, WaitHandle> > responseDict)
        {
            List <string> new_view = new List <string>();

            //Console.WriteLine("Current View: ");
            foreach (var entry in responseDict)
            {
                if (entry.Value.Value.WaitOne(0))
                {
                    AsyncPingDelegate del = (AsyncPingDelegate)((AsyncResult)entry.Value.Key).AsyncDelegate;
                    try
                    {
                        del.EndInvoke(entry.Value.Key);
                        //Console.WriteLine(entry.Key);
                        new_view.Add(entry.Key);
                    }
                    catch (Exception error)
                    {
                        //Do nothing, the server is really dead or is behaving badly.
                        //Console.WriteLine("VIEW MANAGER: A pingable is behaving weirdly, check it out");
                        //Console.WriteLine(error.ToString());
                    }
                }
                else
                {
                    //Console.WriteLine("Ups");
                    //Server is probably alive but he just timed out or is not currently responding
                    //Assume that it died, he will come back eventually if he really is alive.
                    //When you don't use EndInvoke you simply dont get the return value.
                }
            }
            return(new_view);
        }
示例#3
0
        public static void RemoteAsyncCallBackPing(IAsyncResult ar)
        {
            AsyncPingDelegate del = (AsyncPingDelegate)((AsyncResult)ar).AsyncDelegate;

            del.EndInvoke(ar);
        }