Esempio n. 1
0
        internal static void PostEvent(StorageEvent ev)
        {
            /// We are using timer to process events instead of a separate message loop
            /// thread, to keep it light weight.

            Timer messagePseudoThread = new Timer(MessageHandler, ev, 10, Timeout.Infinite);
        }
        public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time)
        {
            StorageEvent ev = new StorageEvent();
            ev.EventType = (StorageEventType)(data1 & 0xFF);
            ev.Handle = data2;
            ev.Time = time;

            return ev;
        }
Esempio n. 3
0
        public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time)
        {
            StorageEvent ev = new StorageEvent();

            ev.EventType = (StorageEventType)(data1 & 0xFF);
            ev.Handle    = data2;
            ev.Time      = time;

            return(ev);
        }
Esempio n. 4
0
        private static void MessageHandler(object args)
        {
            try
            {
                StorageEvent ev = args as StorageEvent;

                if (ev == null)
                {
                    return;
                }

                lock (_volumes)
                {
                    if (ev.EventType == StorageEventType.Insert)
                    {
                        VolumeInfo volume = new VolumeInfo(ev.Handle);

                        _volumes.Add(volume);

                        if (Insert != null)
                        {
                            MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                            Insert(null, mediaEventArgs);
                        }
                    }
                    else if (ev.EventType == StorageEventType.Eject)
                    {
                        VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                        if (volumeInfo != null)
                        {
                            FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                            if (Eject != null)
                            {
                                MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                                Eject(null, mediaEventArgs);
                            }
                        }
                    }
                }
            }
            finally
            {
                // get rid of this timer
                _events.Dequeue();
            }
        }
Esempio n. 5
0
 internal static void PostEvent(StorageEvent ev)
 {
     /// We are using timer to process events instead of a separate message loop
     /// thread, to keep it light weight.
     try
     {
         // create a time and push it in a queue to make sure GC does not eat it up before it fires
         // the timer will pop itself in the callback and GC will take it from there
         // be trasaction-safe and create and queue the timer before setting it up to fire
         Timer messagePseudoThread = new Timer(MessageHandler, ev, Timeout.Infinite, Timeout.Infinite);
         _events.Enqueue(messagePseudoThread);
         // now that all operation that can fail have been done, enable the timer to fire
         messagePseudoThread.Change(10, Timeout.Infinite);
     }
     catch // eat up all exceptions, nothing we can do
     {
     }
 }
Esempio n. 6
0
        private static void MessageHandler(object args)
        {
            StorageEvent ev = args as StorageEvent;

            if (ev == null)
            {
                return;
            }

            if (ev.EventType == StorageEventType.Insert)
            {
                VolumeInfo volume = new VolumeInfo(ev.Handle);

                _volumes.Add(volume);

                if (Insert != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(volume, ev.Time);

                    Insert(null, mediaEventArgs);
                }
            }
            else if (ev.EventType == StorageEventType.Eject)
            {
                VolumeInfo volumeInfo = RemoveVolume(ev.Handle);

                FileSystemManager.ForceRemoveNameSpace(volumeInfo.Name);

                if (Eject != null)
                {
                    MediaEventArgs mediaEventArgs = new MediaEventArgs(new VolumeInfo(volumeInfo), ev.Time);

                    Eject(null, mediaEventArgs);
                }
            }
        }
 internal static void PostEvent(StorageEvent ev)
 {
     /// We are using timer to process events instead of a separate message loop
     /// thread, to keep it light weight.
     try
     {
         // create a time and push it in a queue to make sure GC does not eat it up before it fires
         // the timer will pop itself in the callback and GC will take it from there
         // be trasaction-safe and create and queue the timer before setting it up to fire
         Timer messagePseudoThread = new Timer(MessageHandler, ev, Timeout.Infinite, Timeout.Infinite);
         _events.Enqueue(messagePseudoThread);
         // now that all operation that can fail have been done, enable the timer to fire
         messagePseudoThread.Change(10, Timeout.Infinite);
     }
     catch // eat up all exceptions, nothing we can do
     {
     }
 }
Esempio n. 8
0
        internal static void PostEvent(StorageEvent ev)
        {
            /// We are using timer to process events instead of a separate message loop
            /// thread, to keep it light weight.

            Timer messagePseudoThread = new Timer(MessageHandler, ev, 10, Timeout.Infinite);
        }