Beispiel #1
0
        private void ToolStripMenuItemAboutComputer_Click(object sender, EventArgs e)
        {
            //将方法指向委托
            GetInfo task = GetSystemInfo;

            //开始异步执行方法,执行完毕,在回调方法中完成后面的任务
            task.BeginInvoke(GetSystemInfoCompleted, task);
        }
Beispiel #2
0
        void timer_Tick_About(object sender, EventArgs e)
        {
            time += 500;
            if (time == TIME_TOOLTIP) // когда прошло нужное количество времени, запрашиваем данные о пользователе
            {
                tip.Hide(this);
                vk start = new vk();

                GetPhoto getPhoto = new GetPhoto(start.getPhoto);
                IAsyncResult res1 = getPhoto.BeginInvoke(uid, "medium", null, null);

                while (!res1.IsCompleted)
                    Application.DoEvents();

                res1.AsyncWaitHandle.WaitOne();
                photo = getPhoto.EndInvoke(res1);
            //                photo = start.getPhoto(uid, "medium");

                if (photo == null)
                {
                    if (File.Exists(vars.VARS.Directory + "\\medium\\" + uid.ToString()))
                        try
                        {
                            photo = Image.FromFile(vars.VARS.Directory + "\\medium\\" + uid.ToString());
                        }
                        catch (OutOfMemoryException exe)
                        {
                            GeneralMethods.WriteError(exe.Source, exe.Message, exe.TargetSite);
                        }
                    else
                    {
                        timer.Stop();
                        time = 0;
                        return;
                    }
                }

                GetInfo getInfo = new GetInfo(start.getInfo);
                IAsyncResult res2 = getInfo.BeginInvoke(uid, null, null);

                while (!res2.IsCompleted)
                    Application.DoEvents();

                res1.AsyncWaitHandle.WaitOne();
                System.Collections.Hashtable Info = getInfo.EndInvoke(res2);

                //System.Collections.Hashtable Info = start.getInfo(uid);
                if (Info != null && !Info.ContainsKey("error"))
                {
                    System.Collections.ArrayList Data = (System.Collections.ArrayList)Info["response"];

                    name = Convert.ToString(((System.Collections.Hashtable)Data[0])["first_name"]) + " " + Convert.ToString(((System.Collections.Hashtable)Data[0])["last_name"]);
                    string bdate = Convert.ToString(((System.Collections.Hashtable)Data[0])["bdate"]);
                    phone = Convert.ToString(((System.Collections.Hashtable)Data[0])["mobile_phone"]);

                    string month = "";

                    if (bdate != "")
                    {
                        string[] bday = bdate.Split('.');
                        switch (bday[1]) // месяц текстом чтобы был
                        {
                            case "1": month = "января"; break;
                            case "2": month = "февраля"; break;
                            case "3": month = "марта"; break;
                            case "4": month = "апреля"; break;
                            case "5": month = "мая"; break;
                            case "6": month = "июня"; break;
                            case "7": month = "июля"; break;
                            case "8": month = "августа"; break;
                            case "9": month = "сентября"; break;
                            case "10": month = "октября"; break;
                            case "11": month = "ноября"; break;
                            case "12": month = "декабря"; break;
                        }
                        birthday = bday[0] + " " + month + " " + (bday.Length == 2 ? "" : bday[2]); // формируем строку дня рождения
                    }

                    tip.Size = new Size(220, (photo == null) ? 200 : (photo.Height + 40)); // задаём размер подсказки
                    tip.Show(uid.ToString(), this, this.ClientRectangle.X + this.Width, this.PointToClient(Control.MousePosition).Y); // показываем подсказку
                }
                timer.Stop();
                time = 0;
            }
            //throw new NotImplementedException();
        }