Example #1
0
 public Form1()
 {
     InitializeComponent();
     objClass obj = new objClass();
     obj.lable = this.label2;
     obj.notify = this.notifyIcon1;
     object objectLable = label2;
     object objectNotify = notifyIcon1;
     //ThreadStart starter = delegate { chcls.check(label2, notifyIcon1); };
     checkThread = new Thread(chcls.check);
     checkThread.Name = "Check";
     checkThread.Start(obj);
 }
Example #2
0
        public void check(object obj)
        {
            objClass objclass = new objClass();
            objclass = (objClass)obj;

            string sURL = Settings.Default.dataAddr;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sURL);

            request.Method = "GET";
            request.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception e)
            {
                //logFile.WriteLine(e);
                System.Console.WriteLine(e);
            }

            try
            {
                resStream = response.GetResponseStream();
            }
            catch(Exception e)
            {
                //logFile.WriteLine(e);
                System.Console.WriteLine(e);
            }

            try
            {
                using (StreamReader objReader = new StreamReader(resStream))
                {
                    // parse json
                    string json = objReader.ReadToEnd();
                    JObject o = JObject.Parse(json);
                    ticketTitle = (string)o["title"];

                    System.Console.WriteLine(ticketTitle+" and "+ticketId);

                    string str = objReader.ReadToEnd();
                    Label lable = (Label)objclass.lable;
                    NotifyIcon notify = (NotifyIcon)objclass.notify;

                    if (ticketId != (string)o["count"] && ticketId != null)
                    {
                        try
                        {
                            lable.Invoke(new MethodInvoker(delegate { playAlert(); notify.BalloonTipText = ticketTitle; notify.ShowBalloonTip(500); }));
                        }
                        catch (Exception e)
                        {
                            //logFile.WriteLine(e.ToString());
                            System.Console.WriteLine(e);
                        }
                    }
                    ticketId = (string)o["count"];
                    try
                    {
                        Thread.Sleep(1000);
                        // in this place was error
                        lable.Invoke(new MethodInvoker(delegate { lable.Text = (string)o["count"]; }));
                    }
                    catch (Exception e)
                    {
                        //logFile.WriteLine(e);
                        System.Console.WriteLine(e.ToString());
                    }

                }

            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            Thread.Sleep(20000);
            Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false));
            GC.Collect();
            check(obj);
        }