Example #1
0
        public IAsyncResult BeginGetDetails(string city, string station, bool refresh, AsyncCallback callback, object state)
        {
            var asyncResult = new SimpleAsyncResult <List <string> >(state);

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

            timer.Elapsed += (_, args) =>
            {
                asyncResult.Result      = GetDetails(city, station, refresh);
                asyncResult.IsCompleted = true;
                callback(asyncResult);
                timer.Enabled = false;
                timer.Close();
            };
            timer.Enabled = true;
            return(asyncResult);
        }
Example #2
0
        public IAsyncResult BeginGetCities(AsyncCallback callback, object state)
        {
            var asyncResult = new SimpleAsyncResult <string[]>(state);

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

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