GLib.IOChannel.AddWatch Method
Adds a notification watch to the mainloop at a given priority.


public uint AddWatch (int priority, IOCondition condition, IOFunc func)


Priority level. Default priority is 0. System defined values range from -100 (High priority) to 300 (Low priority).
Conditions to notify.
Notification callback delegate.


A source ID which can be removed with Source.Remove.


The following example spawns a process to run the pwd command and writes the output to the console using an IOChannel watch:

C# Example

using GLib;
using System;

public class SpawnTest  {

	public static void Main (string[] args)
		new SpawnTest ();

	MainLoop main_loop;
	IOChannel channel;

	public SpawnTest ()
		main_loop = new MainLoop ();

		try {
			Process proc;
			int stdin = Process.IgnorePipe;
			int stdout = Process.RequestPipe;
			int stderr = Process.IgnorePipe;
			GLib.Process.SpawnAsyncWithPipes (null, new string[] {"pwd"}, null, SpawnFlags.SearchPath, null, out proc, ref stdin, ref stdout, ref stderr);
			channel = new IOChannel (stdout);
			channel.AddWatch (0, IOCondition.In | IOCondition.Hup, new IOFunc (ReadStdout));
		} catch (Exception e) {
			Console.WriteLine ("Exception in Spawn: " + e);

		main_loop.Run ();

	bool ReadStdout (IOChannel source, IOCondition condition)
		if ((condition & IOCondition.In) == IOCondition.In) {
			string txt;
			if (source.ReadToEnd (out txt) == IOStatus.Normal)
				Console.WriteLine ("[SpawnTest output] " + txt);
		if ((condition & IOCondition.Hup) == IOCondition.Hup) {
			source.Dispose ();
			main_loop.Quit ();
			return true;
		return true;


Namespace: GLib
Assembly: glib-sharp (in glib-sharp.dll)