Serializer.PumpEvents

Invokes all outstanding event callbacks on this thread. Does nothing if AsyncCallbacksEnabled is set to true.

public void PumpEvents();

Return Value

void

Remarks

This is handled automatically if the Run() method is used to establish a run loop. If Run() cannot be used (perhaps because the System.Windows.Forms run loop is used instead), then PumpEvents() must be called manually. In the System.Windows.Forms example, invoking this from a System.Windows.Forms.Timer callback is a good solution.

Example

using RoboticsConnection.Serializer;
using RoboticsConnection.Serializer.Ids;
using RoboticsConnection.Serializer.Sensors;
using RoboticsConnection.Serializer.Components;
using RoboticsConnection.Serializer.Controllers;
using System;

namespace test
{
	class Program
	{
		static Serializer serializer;
		static SP03 speaker;

		static void Main(string[] args)
		{
			serializer = new Serializer();
			speaker = new SP03(serializer);

			serializer.CommunicationStarted += new SerializerEventHandler(serializer_CommunicationStarted);
			serializer.StartCommunication();

			// NOTE: This is exactly what happens in the call to Run(), except
			// you can do things in between calling PumpEvents() in this case.
			while (true)
			{
				// Handle outstanding events to be fired...
				// (such as an ir sensor's distance has surpassed
				//  the specified threshold, and an event needs to
				//  be fired to those listening for the event.
				serializer.PumpEvents();

				// Do other stuff here, such as read sensors, turn on/off motors, etc.
			}
		}

		static void serializer_CommunicationStarted(Serializer sender)
		{
			speaker.Speak("Hello World!");
		}
	}
}

See also:

Class Serializer


Last Updated: 1/9/2007