Exemplo n.º 1
0
        private void Run()
        {
            while (true)
            {
                // wait for the thread to be woken
                iEvent.WaitOne();
                Trace.WriteLine(Trace.kCore, "WebRequestThread.Run() wake on thread " + iThread.Name);

                // check for termination
                if (iJob == null)
                {
                    break;
                }

                // run the job
                try
                {
                    iJob.Execute();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(Trace.kCore, "WebRequestThread.Run() exception on thread " + iThread.Name);
                    Trace.WriteLine(Trace.kCore, e);
                }

                // clear the job and notify the WebRequestPool
                iJob = null;
                iEvent.Reset();

                Trace.WriteLine(Trace.kCore, "WebRequestThread.Run() finished on thread " + iThread.Name);

                WebRequestPool.JobFinished(this);
            }
        }
Exemplo n.º 2
0
        public void Execute()
        {
            Stream reqStream = null;

            try
            {
                reqStream = iRequest.GetRequestStream();
                reqStream.Write(iMessage, 0, iMessage.Length);
            }
            catch(Exception ex)
            {
                Trace.WriteLine(Trace.kCore, "Exception caught sending HttpWebRequest: " + ex);
            }
            finally
            {
                if (reqStream != null)
                {
                    reqStream.Close();
                    reqStream.Dispose();
                }
            }

            WebRequestPool.QueueJob(new JobGetResponse(iCallback, iRequest));
        }