static void ReceiveDemoAsync() { // demonstrate receiving asynchrnously - ReceiveAsync processes messages as and when they arrive. // Open another instance to send messages while the other receives. IBus bus = new BusBuilder() .WithLogging(new ConsoleLogger()) .InstallMsmqIfNeeded() .DefineErrorQueue("MiniBus.errors") .DefineReadQueue("MiniBus.messages1") .CreateLocalQueuesAutomatically() .EnlistInAmbientTransactions() .JsonSerialization() .NumberOfRetries(3) .CreateBus(); bus.RegisterHandler(new PersonHandler(false)); bus.ReceiveAsync <Person>(); Console.WriteLine("\nPress a key to exit"); Console.ReadLine(); bus.Dispose(); }
//static void Main(string[] args) public Boat(int M, int N) { string[] ms = new string[M + N]; var processInfo = new ProcessStartInfo { //UseShellExecute = false, // redirect all input/output streams to parent's console FileName = Constants.FILENAME_PASSENGER, Arguments = Constants.ARGUMENT_PASSENGER_M_MISIONARA }; for (int i = 0; i < M; i++) { // create missionary var pid = i; //new Passenger(pid, false); // TO DO: start process processInfo.Arguments = pid + " " + Constants.ARGUMENT_PASSENGER_M_MISIONARA; childProcesses.Add(Process.Start(processInfo)); ms.Append(pre + pid); } for (int i = 0; i < N; i++) { // create cannibal var pid = i + M; //new Passenger(pid, false); // TO DO: start process processInfo.Arguments = pid + " " + Constants.ARGUMENT_PASSENGER_M_MISIONARA; childProcesses.Add(Process.Start(processInfo)); ms.Append(pre + pid); } // create a bus for receiving messages IBus bus = new BusBuilder() .WithLogging(new ConsoleLogger()) .DefineErrorQueue("Boat.errors") .DefineReadQueue("Boat") //.DefineWriteQueues(ms) .CreateLocalQueuesAutomatically() .JsonSerialization() .CreateBus(); // register one or more message handlers bus.RegisterHandler <Message>(new PassengerHandler()); // process messages on the read queue synchronously bus.ReceiveAsync <Message>(); // bus.ReceiveAsync<PlaceOrder>(); aTimer = new Timer(Constants.BOAT_CHECK_PERIOD); aTimer.Elapsed += (sender, args) => { //bus.StopReceiving(); if (!ProcessPassengers()) { // bus.Receive<Message>(); //} //else //{ // die aTimer.Enabled = false; Console.WriteLine("Press enter to exit..."); Console.ReadLine(); } }; aTimer.AutoReset = true; aTimer.Enabled = true; }