Ejemplo n.º 1
0
        public IAsyncResult BegingetTowns(AsyncCallback callback, object state)
        {
            var asyncResult = new SimpleAsyncResult <IList <string> >(state);

            // mimic a long running operation
            var timer = new System.Timers.Timer(DelayMilliseconds);

            timer.Elapsed += (_, args) =>
            {
                asyncResult.Result      = getTowns();
                asyncResult.IsCompleted = true;
                callback(asyncResult);
                timer.Enabled = false;
                timer.Close();
            };
            timer.Enabled = true;
            return(asyncResult);
        }
Ejemplo n.º 2
0
        public IAsyncResult BegingetAvailableBikes(string town, string station, int time, AsyncCallback callback, object state)
        {
            var asyncResult = new SimpleAsyncResult <int>(state);

            // mimic a long running operation
            var timer = new System.Timers.Timer(DelayMilliseconds);

            timer.Elapsed += (_, args) =>
            {
                asyncResult.Result      = getAvailableBikes(town, station, time);
                asyncResult.IsCompleted = true;
                callback(asyncResult);
                timer.Enabled = false;
                timer.Close();
            };
            timer.Enabled = true;
            return(asyncResult);
        }