Пример #1
0
 static T GetWorkResult <T>(IAsyncResult i) where T : DiceResponse
 {
     using (DiceAsyncResult <T> res = (DiceAsyncResult <T>)i)
     {
         if (!res.IsCompleted)
         {
             res.AsyncWaitHandle.WaitOne();
         }
         Exception e = res.Exception;
         if (e != null)
         {
             throw e;
         }
         return(res.Response);
     }
 }
Пример #2
0
        static DiceAsyncResult <T> QueueWork <T>(AsyncCallback callback, object state, Func <T> work) where T : DiceResponse
        {
            DiceAsyncResult <T> resp = new DiceAsyncResult <T>(callback, state);

            ThreadPool.QueueUserWorkItem(x =>
            {
                try
                {
                    resp.Complete(work());
                }
                catch (Exception e)
                {
                    resp.Complete(e);
                }
            });
            return(resp);
        }