Beispiel #1
0
 public override void ViewDidDisappear(bool animated)
 {
     base.ViewDidDisappear(animated);
     if (dispatchSource != null)
     {
         dispatchSource.Cancel();
     }
 }
        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);
            if (testFileStream != null)
            {
                testFileStream.Dispose();
            }

            if (dispatchSource != null)
            {
                dispatchSource.Cancel();
                dispatchSource.Dispose();
            }
        }
Beispiel #3
0
        void TestReadMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            File.WriteAllText(fileURL.Path, "Roses are red");
            var stream         = File.OpenRead(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new CoreFoundation.DispatchSource.ReadMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Read monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                PrintResult(textView, string.Format("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Read monitor cancelled");
            });

            dispatchSource.Resume();
        }
Beispiel #4
0
        void StartWriteMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            var stream         = File.Create(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.WriteMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Write monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                string message = string.Format("Write monitor: {0} was opened in write mode", fileURL.LastPathComponent.ToString());
                PrintResult(textView, message);
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Write monitor cancelled");
            });

            dispatchSource.Resume();
        }
Beispiel #5
0
        void StartVnodeMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            var stream         = File.Create(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.VnodeMonitor(fileDescriptor,
                                                             VnodeMonitorKind.Delete | VnodeMonitorKind.Extend | VnodeMonitorKind.Write,
                                                             DispatchQueue.MainQueue
                                                             );

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Vnode monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                var observedEvents = ((DispatchSource.VnodeMonitor)dispatchSource).ObservedEvents;
                string message     = string.Format("Vnode monitor event for {0}: {1}", fileURL.LastPathComponent, observedEvents.ToString());
                PrintResult(textView, message);
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Vnode monitor cancelled");
            });

            dispatchSource.Resume();
        }
        void TestReadMonitor()
        {
            NSUrl fileURL        = TestFileUrl;
            int   fileDescriptor = 0;

            using (var stream = new FileStream(fileURL.Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) {
                fileDescriptor = GetFileDescriptor(stream);
            }

            dispatchSource = new DispatchSource.ReadMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Read monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                PrintResult(textView, string.Format("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
                dispatchSource.Cancel();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Read monitor cancelled");
            });

            dispatchSource.Resume();
        }
 public override void ViewWillDisappear(bool animated)
 {
     base.ViewWillDisappear(animated);
     dispatchSource.Cancel();
     dispatchSource.Dispose();
     dispatchSource = null;
 }
 private void CancelDispatchSource()
 {
     if (dispatchSource != null)
     {
         dispatchSource.Cancel();
         dispatchSource.Dispose();
         dispatchSource = null;
     }
 }
Beispiel #9
0
        void StartMemoryMonitor()
        {
            dispatchSource = new DispatchSource.MemoryPressure(
                MemoryPressureFlags.Critical | MemoryPressureFlags.Warn | MemoryPressureFlags.Normal,
                DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Memory monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                var pressureLevel = ((DispatchSource.MemoryPressure)dispatchSource).PressureFlags;
                PrintResult(textView, string.Format("Memory worning of level: {0}", pressureLevel));
                tableView.UserInteractionEnabled = true;
                dispatchSource.Cancel();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Memory monitor cancelled");
            });

            dispatchSource.Resume();
        }
		void TestReadMonitor ()
		{
			NSUrl fileURL = TestFileUrl;
			int fileDescriptor = 0;

			using (var stream = new FileStream (fileURL.Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) {
				fileDescriptor = GetFileDescriptor (stream);
			}

			dispatchSource = new DispatchSource.ReadMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Read monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				PrintResult (textView, string.Format ("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
				dispatchSource.Cancel ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Read monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartWriteMonitor ()
		{
			NSUrl fileURL = TestFileUrl;
			var stream = new FileStream (fileURL.Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
			int fileDescriptor = GetFileDescriptor (stream);

			dispatchSource = new DispatchSource.WriteMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Write monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				string message = string.Format ("Write monitor: {0} was opened in write mode", fileURL.LastPathComponent);
				PrintResult (textView, message);
				dispatchSource.Cancel ();
				stream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Write monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartMemoryMonitor ()
		{
			dispatchSource = new DispatchSource.MemoryPressure (
				MemoryPressureFlags.Critical | MemoryPressureFlags.Warn | MemoryPressureFlags.Normal, 
				DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Memory monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				var pressureLevel = ((DispatchSource.MemoryPressure)dispatchSource).PressureFlags;
				PrintResult (textView, string.Format ("Memory worning of level: {0}", pressureLevel));
				tableView.UserInteractionEnabled = true;
				dispatchSource.Cancel ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Memory monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartVnodeMonitor ()
		{
			NSUrl fileURL = TestFileUrl;

			testFileStream = File.Create (fileURL.Path);
			int fileDescriptor = GetFileDescriptor (testFileStream);

			dispatchSource = new DispatchSource.VnodeMonitor (fileDescriptor,
				VnodeMonitorKind.Delete | VnodeMonitorKind.Extend | VnodeMonitorKind.Write,
				DispatchQueue.MainQueue
			);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Vnode monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				var observedEvents = ((DispatchSource.VnodeMonitor)dispatchSource).ObservedEvents;
				string message = string.Format ("Vnode monitor event for {0}: {1}", fileURL.LastPathComponent, observedEvents);
				PrintResult (textView, message);
				dispatchSource.Cancel ();
				testFileStream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Vnode monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void TestReadMonitor ()
		{
			NSUrl fileURL = TestFileUrl;

			File.WriteAllText (fileURL.Path, "Roses are red");
			var stream = File.OpenRead (fileURL.Path);
			int fileDescriptor = GetFileDescriptor (stream);

			dispatchSource = new CoreFoundation.DispatchSource.ReadMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Read monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				PrintResult (textView, string.Format ("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
				dispatchSource.Cancel ();
				stream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Read monitor cancelled");
			});

			dispatchSource.Resume ();
		}