コード例 #1
0
        private void OnRemovedFromCache(CacheEntryRemovedArguments arguments)
        {
            if (arguments.RemovedReason != CacheEntryRemovedReason.Expired)
            {
                return;
            }

            new Thread(
                delegate()
            {
                FileSystemWatcherEventDescription myEventDescription = (FileSystemWatcherEventDescription)arguments.CacheItem.Value;
                switch (myEventDescription.type)
                {
                case EventIDs.CREATED:
                    HandleCreatedEvent(myEventDescription.currentFilePath);
                    break;

                case EventIDs.CHANGED:
                    HandleChangedEvent(myEventDescription.currentFilePath);
                    break;

                case EventIDs.RENAMED:
                    HandleRenamedEvent(myEventDescription.previousFilePath, myEventDescription.currentFilePath);
                    break;

                case EventIDs.DELETED:
                    HandleDeletedEvent(myEventDescription.currentFilePath);
                    break;

                default:
                    break;
                }
            }
                ).Start();
        }
コード例 #2
0
        private void OnChanged(object source, FileSystemEventArgs myEvent)
        {
            cacheItemPolicy.AbsoluteExpiration = DateTimeOffset.Now.AddMilliseconds(CACHE_TIME_MILLISECONDS);

            // Only add if it is not there already (swallow others)
            FileSystemWatcherEventDescription eventParameters = new FileSystemWatcherEventDescription()
            {
                type             = EventIDs.CHANGED,
                currentFilePath  = myEvent.FullPath,
                previousFilePath = null
            };

            memoryCache.AddOrGetExisting($"{myEvent.FullPath}_Changed", eventParameters, cacheItemPolicy);
        }