public void f_runLoop(IJobHandle handle) { // Create the token source. CancellationTokenSource cts = new CancellationTokenSource(); /* 4: stop */ if (this.Status == 4) { f_sleepAfterLoop(handle); } /* 1: init */ if (this.Status == 1) { System.Tracer.WriteLine("J{0} BASE: INITED ...", this.Id); this.Handle = handle; this.f_init(); this.Status = 2; /* 2: running */ f_runLoop(handle); } /* 2: running */ if (this.Status == 2) { Message m = null; if (this.Handle.Factory == null) { m = this.Messages.Dequeue(null); } else { m = this.Handle.Factory.f_getMessage(null); } if (m == null) { //Tracer.WriteLine("J{0} BASE: WAITING ...", this.Id); // WAITING TO RECEIVED MESSAGE ... f_sleepAfterLoop(handle); } else { //Tracer.WriteLine("J{0} BASE: PROCESSING ...", this.Id); // PROCESSING MESSAGE ProcessMessage fun = this.f_processMessage; IAsyncResult asyncRes = fun.BeginInvoke(m, new AsyncCallback(f_callbackProcessMessage), null); ///// check timeout ... //IAsyncResult asyncRes = fun.BeginInvoke(m, null, null); //// Poll IAsyncResult.IsCompleted //while (asyncRes.IsCompleted == false) //{ // Console.WriteLine("Square Number still processing"); // Thread.Sleep(1000); // emulate that method is busy //} //Console.WriteLine("Square Number processing completed"); //Guid res = fun.EndInvoke(asyncRes); } } /// end function /////////////////////// }