示例#1
0
        private async Task <PPError> CloseAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <PPError>();
            EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleClose += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    Close();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        PPBURLLoader.Close(this);
                        tcs.TrySetResult(PPError.Ok);
                    }
                                                                   );
                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(PPError.Aborted);
            }
            finally
            {
                HandleClose -= handler;
            }
        }
示例#2
0
 /// <summary>
 /// This function is used to cancel any pending IO and close the URLLoader
 /// object. Any pending callbacks will still run, reporting
 /// <code>Aborted</code> if pending IO was interrupted.  It is NOT
 /// valid to call Open() again after a call to this function.
 ///
 /// <strong>Note:</strong> If the <code>URLLoader</code> object is destroyed
 /// while it is still open, then it will be implicitly closed so you are not
 /// required to call Close().
 /// </summary>
 public void Close()
 {
     PPBURLLoader.Close(this);
     OnClose(PPError.Ok);
 }