Example #1
0
        private void doWork()
        {
            while (true)
            {
                try
                {
                    string url = "";
                    lock (_in_queue)
                    {
                        while (_in_queue.Count == 0 && !doExit)
                        {
                            Monitor.Wait(_in_queue);
                        }
                        if (doExit)
                        {
                            break;
                        }
                        url = _in_queue.Dequeue();
                    }

                    List <Channel> res = RssFetcher.getFeedFromURL(url);
                    lock (_out_queue)
                    {
                        _out_queue.Enqueue(res);
                        Monitor.Pulse(_out_queue);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
        private void doWork()
        {
            while (true)
            {
                try
                {
                    string url = "";
                    lock (_in_queue)
                    {
                        while (_in_queue.Count == 0 && !doExit)
                        {
                            Monitor.Wait(_in_queue);
                        }
                        if (doExit)
                        {
                            break;
                        }
                        url = _in_queue.Dequeue();
                    }

                    List <Channel> res = RssFetcher.getFeedFromURL(url);

                    var          ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List <Channel>));
                    MemoryStream ms  = new MemoryStream();
                    ser.WriteObject(ms, res);
                    string res_str = Encoding.UTF8.GetString(ms.ToArray());
                    ms.Close();

                    HttpWebRequest request = WebRequest.Create("http://localhost:49714/WebService.svc/enqueue_filter") as HttpWebRequest;
                    request.Method        = "POST";
                    request.ContentType   = "application/json";
                    request.ContentLength = Encoding.UTF8.GetByteCount(res_str);

                    StreamWriter sw = new StreamWriter(request.GetRequestStream());
                    sw.Write(res_str);
                    sw.Close();
                    request.GetResponse();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.Message);
                }
            }
        }