Beispiel #1
0
        static void fs_Changed(object sender, FileSystemEventArgs e)
        {
            FileInfo f = new FileInfo(e.FullPath);

            if (WatchedFiles.Contains(f.Name))
            {
                try
                {
                    string current_hash = GetHash(f.FullName);
                    string key_name     = GetKeyName(f);

                    if (!WatchDictionary.ContainsKey(key_name))
                    {
                        WatchDictionary.Add(key_name, current_hash);
                    }

                    if (current_hash != WatchDictionary[key_name])
                    {
                        var worker = new MyTaskWorkerDelegate(MyTaskWorker);
                        worker.BeginInvoke(key_name, current_hash, null, null);
                    }
                }
                catch (System.Exception ex)
                {
                    System.Console.Write("FileChanged exception:\n {0}", ex);
                }
            }
        }
Beispiel #2
0
        static private void HashDirectory(System.IO.DirectoryInfo directoryInfo)
        {
            FileInfo[] fileInfoSet = directoryInfo.GetFiles();
            foreach (FileInfo fileInfo in fileInfoSet)
            {
                string current_hash = GetHash(fileInfo.FullName);
                string key_name     = GetKeyName(fileInfo);
                if (!WatchDictionary.ContainsKey(key_name))
                {
                    WatchDictionary.Add(key_name, current_hash);
                }

                var worker = new MyTaskWorkerDelegate(MyTaskWorker);
                worker.BeginInvoke(key_name, current_hash, null, null);
            }

            foreach (System.IO.DirectoryInfo di in directoryInfo.GetDirectories())
            {
                string directoryName = di.FullName;

                System.Console.WriteLine(directoryName);

                HashDirectory(di);
            }
        }
Beispiel #3
0
        // Async version of my actual work function
        public void MyTaskAsync(string[] files)
        {
            MyTaskWorkerDelegate worker            = new MyTaskWorkerDelegate(MyTaskWorker);
            AsyncCallback        completedCallback = new AsyncCallback(MyTaskCompletedCallback);

            lock (_sync)
            {
                if (_myTaskIsRunning)
                {
                    throw new InvalidOperationException("The control is currently busy.");
                }

                AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                worker.BeginInvoke(files, completedCallback, async);
                _myTaskIsRunning = true;
            }
        }
Beispiel #4
0
        public void MyTaskAsync(string[] files)
        {
            MyTaskWorkerDelegate worker = new MyTaskWorkerDelegate(MyTaskWorker);
            AsyncCallback completedCallback = new AsyncCallback(MyTaskCompletedCallback);

            lock (_sync)
            {
                if (_myTaskIsRunning)
                    throw new InvalidOperationException("The control is currently busy.");

                AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                MyAsyncContext context = new MyAsyncContext();
                bool cancelled;

                worker.BeginInvoke(files, async, context, out cancelled, completedCallback, async);

                _myTaskIsRunning = true;
                _myTaskContext = context;
            }
        }