Пример #1
0
 static void OnFileActivityFinishedEvent(object sender, FileActivityFinishedEventArgs e)
 {
     lock (Lock)
     {
         Console.WriteLine("OnFileActivityFinishedEvent:");
         Console.WriteLine();
     }
 }
 /// <summary>
 /// Template method to add default behaviour for the event
 /// </summary>
 private void OnFileActivityFinishedEvent(FileActivityFinishedEventArgs e)
 {
     // TODO: Implement default behaviour of OnFileActivityFinishedEvent
 }
        /// <summary>
        /// Will raise the event on the current thread synchronously.
        /// i.e. it will wait until all event handlers have processed the event.
        /// </summary>
        /// <param name="e">The state to be passed to the event.</param>
        private void RaiseOnFileActivityFinishedEvent(FileActivityFinishedEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.

            FileActivityFinishedEventHandler eventHandler;

            if (!Monitor.TryEnter(_fileActivityFinishedEventLock, _lockTimeout))
            {
                throw new ApplicationException("Timeout waiting for lock - RaiseOnFileActivityFinishedEvent");
            }
            try
            {
                eventHandler = _fileActivityFinishedEvent;
            }
            finally
            {
                Monitor.Exit(_fileActivityFinishedEventLock);
            }

            OnFileActivityFinishedEvent(e);

            if (eventHandler != null)
            {
                eventHandler(this, e);
            }
        }
 /// <summary>
 /// Will raise the event on the calling thread synchronously. 
 /// i.e. it will wait until all event handlers have processed the event.
 /// </summary>
 /// <param name="state">The state to be passed to the event.</param>
 private void RaiseCrossThreadOnFileActivityFinishedEvent(FileActivityFinishedEventArgs e)
 {
     _asyncOperation.SynchronizationContext.Send(new SendOrPostCallback(AsynchronousOnFileActivityFinishedEventRaised), e);
 }
 /// <summary>
 /// Will raise the event on the calling thread asynchronously. 
 /// i.e. it will immediatly continue processing even though event 
 /// handlers have not processed the event yet.
 /// </summary>
 /// <param name="state">The state to be passed to the event.</param>
 private void RaiseAsynchronousOnFileActivityFinishedEvent(FileActivityFinishedEventArgs e)
 {
     _asyncOperation.Post(new SendOrPostCallback(AsynchronousOnFileActivityFinishedEventRaised), e);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks>It is assumed that there will be no file events once this has been raised. Chances are that file 
 /// events are going to occur, so its up to the calling client to switch off the file watcher while processing if necessary.</remarks>
 private void OnTimeUpForFileActivityFinished(object sender, ElapsedEventArgs e)
 {
     _timerForFileActivityFinished.Stop();
     var fileEventItems = new List<IFileEventItem>(_fileEventItems);
     _fileEventItems.Clear();
     var activityFinishedEventArgs = new FileActivityFinishedEventArgs(fileEventItems, UserState);
     RaiseAsynchronousOnFileActivityFinishedEvent(activityFinishedEventArgs);
 }