示例#1
0
 public Pet(ICallBackRequired player, IPetPersistence petdataobj)           // Inject messages channel to Player thread and pet data object
 {
     requirefeed     = new AsyncPlayerFunctionPointer(player.FeedRequired); // Set function pointers to Player methods
     requirebed      = new AsyncPlayerFunctionPointer(player.BedRequired);
     requireclean    = new AsyncPlayerFunctionPointer(player.CleanRequired);
     playerMessaging = new AsyncPlayerMessagingPointer(player.MessageReceived);
     petdata         = petdataobj;
     eventList       = new List <PetEvents>();
     rnd             = new Random();
 }
示例#2
0
        private void AsyncFunctionCallBack(IAsyncResult r) // Async Call Completes
        {
            AsyncResult result = (AsyncResult)r;

            if (result.AsyncDelegate is AsyncPlayerFunctionPointer)
            {
                AsyncPlayerFunctionPointer caller = (AsyncPlayerFunctionPointer)result.AsyncDelegate;
                caller.EndInvoke(r);
                return;
            }
            if (result.AsyncDelegate is AsyncPlayerMessagingPointer)
            {
                AsyncPlayerMessagingPointer caller = (AsyncPlayerMessagingPointer)result.AsyncDelegate;
                caller.EndInvoke(r);
                return;
            }
            throw new Exception("Invalid AsyncDelegate Type");
        }