Asynchronouse Event

I noticed that events block when raised! Can i make the event asynchronous and is this best practice?

        #region Event Delegates
        public delegate void OnPlaybackFinishedHandler();
        #endregion

        #region Events
        public static event OnPlaybackFinishedHandler PlaybackFinished;
        public static void OnPlayBackEvent()
        {
            Thread.Sleep(1000);
            Debug.Print("OnPlayBackEvent[" + System.Environment.TickCount + "]..");
             //do stuff
            Debug.Print("...OnPlayBackEvent[" + System.Environment.TickCount + "]");

        }
        #endregion      



  static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
        {
            OnPlayBackEvent();
             //do stuff
        }

I want to trigger some logging that may/maynot send a message to the cloud, hence their could be a delay but i don’t want it to block.

The interrupt is going to blink an led and i don’t want that to be delayed by the logging? Hope that makes sense?

Wouldn’t a thread have too much overhead if its triggered multiple times per second?

A solution could be a Class with a queue and a thread running in a loop, writing the contents of the queue to the cloud. The queue would be filled from the eventhandler.

@ RoSchmi - Thanks. I did think of this method and you have confirmed it :slight_smile: