コード例 #1
0
ファイル: Form1.cs プロジェクト: Jiang0407/SouGouReading
        private void SGstart_Click(object sender, EventArgs e)
        {
            if (MaxNum.Text == "")
            {
                MaxNum.Text = "10";
            }
            if (Delaytime.Text == "")
            {
                Delaytime.Text = "10";
            }
            int           Num    = Convert.ToInt16(MaxNum.Text);
            int           time   = Convert.ToInt16(Delaytime.Text);
            List <string> Result = new List <string>();
            Thread        t      = new Thread(new ThreadStart(delegate
            {
                for (int i = 0; i < Num; i++)
                {
                    string tmp = SG_main();
                    if (tmp != "")
                    {
                        SGstatus.BeginInvoke(new EventHandler(delegate
                        {
                            SGstatus.AppendText(tmp);
                        }));
                        Result.Add(tmp);
                    }
                    else
                    {
                        i--;
                    }
                    Thread.Sleep(time * 1000);
                }
                WriteListToTextFile(Result, "./save.txt");
                SGstatus.BeginInvoke(new EventHandler(delegate
                {
                    SGstatus.AppendText("任务完成\n");
                }));
            }));

            t.IsBackground = true;
            t.Start();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Jiang0407/SouGouReading
        //帐号信息查询

        private void RKSignIn_Click(object sender, EventArgs e)
        {
            if (RKname.Text == "" || RKpasswd.Text == "")
            {
                SGstatus.AppendText("请输入若快账号与密码\n");
                return;
            }
            var param = new Dictionary <object, object>
            {
                { "username", RKname.Text },
                { "password", RKpasswd.Text }
            };


            Thread t = new Thread(new ThreadStart(delegate
            {
                //提交服务器
                string httpResult  = RuoKuai.RuoKuaiHttp.Post("http://api.ruokuai.com/info.xml", param);
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(httpResult);
                }
                catch
                {
                    SGstatus.BeginInvoke(new EventHandler(delegate
                    {
                        SGstatus.AppendText("返回格式有误\r\n");
                        SGstatus.Select(SGstatus.TextLength, SGstatus.TextLength);
                        SGstatus.ScrollToCaret();
                    }));
                }


                XmlNode scoreNode        = xmlDoc.SelectSingleNode("Root/Score");
                XmlNode historyScoreNode = xmlDoc.SelectSingleNode("Root/HistoryScore");
                XmlNode totalTopicNode   = xmlDoc.SelectSingleNode("Root/TotalTopic");

                XmlNode errorNode = xmlDoc.SelectSingleNode("Root/Error");

                if (scoreNode != null && historyScoreNode != null && totalTopicNode != null)
                {
                    SGstatus.BeginInvoke(new EventHandler(delegate
                    {
                        SGstatus.AppendText("剩余快豆:" + scoreNode.InnerText + "\r\n");
                        SGstatus.AppendText("历史快豆:" + historyScoreNode.InnerText + "\r\n");
                        SGstatus.AppendText("答题总数:" + totalTopicNode.InnerText + "\r\n");
                        SGstatus.Select(SGstatus.TextLength, SGstatus.TextLength);
                        SGstatus.ScrollToCaret();
                    }));
                }
                else if (errorNode != null)
                {
                    SGstatus.BeginInvoke(new EventHandler(delegate
                    {
                        SGstatus.AppendText("错误:" + errorNode.InnerText + "\r\n");
                        SGstatus.Select(SGstatus.TextLength, SGstatus.TextLength);
                        SGstatus.ScrollToCaret();
                    }));
                }
                else
                {
                    SGstatus.BeginInvoke(new EventHandler(delegate
                    {
                        SGstatus.AppendText("未知问题\r\n");
                        SGstatus.Select(SGstatus.TextLength, SGstatus.TextLength);
                        SGstatus.ScrollToCaret();
                    }));
                }
            }));

            t.IsBackground = true;
            t.Start();
        }