A class that handles the event functionality.
Inheritance: BaseLock, IDisposable
コード例 #1
0
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    stop();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_threadStopEvent != null)
                        {
                            m_threadStopEvent.Dispose();
                            m_threadStopEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
コード例 #2
0
ファイル: WebRequestEx.cs プロジェクト: wwwyfjp/EpLibrary.cs
        /// <summary>
        /// Get response from the given uri with given credentials
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="credentials">credentials</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        /// <returns></returns>
        public static String GetResponse(String uri, ICredentials credentials = null, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
            {
                throw new Exception("Must supply valid URI!");
            }

            WebClient client = new WebClient(); WebRequest.Create(uri);
            string    result = null;

            if (credentials != null)
            {
                client.Credentials = credentials;
            }
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);

            client.DownloadStringCompleted += (s, e) =>
            {
                result = e.Result;
                doneEvent.SetEvent();
            };
            client.DownloadStringAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
            return(result);
        }
コード例 #3
0
ファイル: WebRequestEx.cs プロジェクト: wwwyfjp/EpLibrary.cs
        /// <summary>
        /// Download file from given uri to given filepath
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="filepath">filepath</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        public static void DownloadFile(String uri, String filepath, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
            {
                throw new Exception("Must supply valid URI!");
            }
            if (filepath == null || filepath.Length == 0)
            {
                throw new Exception("Must supply valid filepath!");
            }
            WebClient webClient = new WebClient();
            EventEx   doneEvent = new EventEx(false, EventResetMode.AutoReset);

            webClient.OpenReadCompleted += (s, e) =>
            {
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        e.Result.CopyTo(stream);
                        stream.Flush();
                        stream.Close();
                        doneEvent.SetEvent();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                }
            };
            webClient.OpenReadAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
        }
コード例 #4
0
 /// <summary>
 /// Default Copy Constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public EventEx(EventEx b) : base(b)
 {
     m_isInitialRaised = b.m_isInitialRaised;
     m_eventResetMode  = b.m_eventResetMode;
     if (m_eventResetMode == EventResetMode.AutoReset)
     {
         m_event = new AutoResetEvent(m_isInitialRaised);
     }
     else
     {
         m_event = new ManualResetEvent(m_isInitialRaised);
     }
 }
コード例 #5
0
ファイル: EventEx.cs プロジェクト: wwwyfjp/EpLibrary.cs
 /// <summary>
 /// Default Copy Constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public EventEx(EventEx b) : base(b)
 {
     m_isInitialRaised = b.m_isInitialRaised;
     m_name            = b.m_name;
     m_eventResetMode  = b.m_eventResetMode;
     if (m_name == null)
     {
         m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
     }
     else
     {
         m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
     }
 }
コード例 #6
0
ファイル: WebRequestEx.cs プロジェクト: juhgiyo/EpLibrary.cs
        /// <summary>
        /// Get response from the given uri with given credentials
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="credentials">credentials</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        /// <returns></returns>
        public static String GetResponse(String uri, ICredentials credentials = null, int waitTimeInMilliSec = Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
                throw new Exception("Must supply valid URI!");

            WebClient client = new WebClient(); WebRequest.Create(uri);
            string result = null;
            if (credentials != null)
                client.Credentials = credentials;
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);
            client.DownloadStringCompleted += (s, e) =>
            {
                result = e.Result;
                doneEvent.SetEvent();
            };
            client.DownloadStringAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
            return result;
        }
コード例 #7
0
ファイル: EventEx.cs プロジェクト: tangyiyong/EpLibrary.cs
        /// <summary>
        /// Default Copy Constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public EventEx(EventEx b):base(b)
        {
            m_isInitialRaised=b.m_isInitialRaised;
	        m_name=b.m_name;
            m_eventResetMode=b.m_eventResetMode;
            if (m_name == null)
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
            else
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
        }
コード例 #8
0
        /// <summary>
        /// Default copy constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public WorkerThreadInfinite(WorkerThreadInfinite  b):base(b)
        {
            m_terminateEvent=new EventEx(false,EventResetMode.AutoReset);
        }
コード例 #9
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="policy">the life policy of this worker thread.</param>
 public WorkerThreadInfinite(ThreadLifePolicy policy):base(policy)
 {
     m_terminateEvent=new EventEx(false,EventResetMode.AutoReset);
 }
コード例 #10
0
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    if (IsConnectionAlive)
                        Disconnect();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_client != null)
                        {
                            m_client.Close();
                            m_client = null;
                        }
                        if (m_timeOutEvent != null)
                        {
                            m_timeOutEvent.Dispose();
                            m_timeOutEvent = null;
                        }
                        if (m_sendEvent != null)
                        {
                            m_sendEvent.Dispose();
                            m_sendEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
コード例 #11
0
 /// <summary>
 /// Default copy constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public WorkerThreadInfinite(WorkerThreadInfinite b) : base(b)
 {
     m_terminateEvent = new EventEx(false, EventResetMode.AutoReset);
 }
コード例 #12
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="policy">the life policy of this worker thread.</param>
 public WorkerThreadInfinite(ThreadLifePolicy policy) : base(policy)
 {
     m_terminateEvent = new EventEx(false, EventResetMode.AutoReset);
 }
コード例 #13
0
ファイル: WebRequestEx.cs プロジェクト: juhgiyo/EpLibrary.cs
        /// <summary>
        /// Download file from given uri to given filepath
        /// </summary>
        /// <param name="uri">uri</param>
        /// <param name="filepath">filepath</param>
        /// <param name="waitTimeInMilliSec">wait time in milliseconds</param>
        public static void DownloadFile(String uri, String filepath, int waitTimeInMilliSec=Timeout.Infinite)
        {
            if (uri == null || uri.Length == 0)
                throw new Exception("Must supply valid URI!");
            if (filepath == null || filepath.Length == 0)
                throw new Exception("Must supply valid filepath!");
            WebClient webClient = new WebClient();
            EventEx doneEvent = new EventEx(false, EventResetMode.AutoReset);
            webClient.OpenReadCompleted += (s, e) =>
            {
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        e.Result.CopyTo(stream);
                        stream.Flush();
                        doneEvent.SetEvent();
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                }
            };
            webClient.OpenReadAsync(new Uri(uri, UriKind.Absolute));
            doneEvent.WaitForEvent(waitTimeInMilliSec);
        }
コード例 #14
0
ファイル: LogWorker.cs プロジェクト: juhgiyo/EpLibrary.cs
        // Protected implementation of Dispose pattern.
        private void Dispose(bool isDisposing)
        {
            try
            {
                if (!this.IsDisposed)
                {
                    stop();
                    if (isDisposing)
                    {
                        // Free any other managed objects here.
                        if (m_threadStopEvent != null)
                        {
                            m_threadStopEvent.Dispose();
                            m_threadStopEvent = null;
                        }
                    }

                    // Free any unmanaged objects here.
                }
            }
            finally
            {
                this.IsDisposed = true;
            }
        }
コード例 #15
0
ファイル: EventEx.cs プロジェクト: tangyiyong/EpLibrary.cs
        /// <summary>
        /// Default Copy Constructor
        /// </summary>
        /// <param name="b">the object to copy from</param>
		public EventEx(EventEx b):base(b)
        {
            m_isInitialRaised=b.m_isInitialRaised;
            m_eventResetMode = b.m_eventResetMode;
            if (m_eventResetMode == EventResetMode.AutoReset)
                m_event = new AutoResetEvent(m_isInitialRaised);
            else
            {
                m_event = new ManualResetEvent(m_isInitialRaised);
            }
        }