Exemple #1
0
        private async Task <PPError> OpenAsyncCore(FileRef fileRef, FileOpenFlags openFlags, MessageLoop openLoop = null)
        {
            var tcs = new TaskCompletionSource <PPError>();
            EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleOpen += handler;

                if (MessageLoop == null && openLoop == null)
                {
                    Open(fileRef, openFlags);
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var result = (PPError)PPBFileIO.Open(this, fileRef, (int)openFlags,
                                                             new BlockUntilComplete()
                                                             );
                        tcs.TrySetResult(result);
                    }
                                                                   );
                    InvokeHelper(action, openLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(PPError.Aborted);
            }
            finally
            {
                HandleOpen -= handler;
            }
        }
Exemple #2
0
 /// <summary>
 /// Open() opens the specified regular file for I/O according to the given
 /// open flags, which is a bit-mask of the FileOpenFlags values.  Upon
 /// success, the corresponding file is classified as "in use" by this FileIO
 /// object until such time as the FileIO object is closed or destroyed.
 /// </summary>
 /// <param name="fileRef">A FileRef instance</param>
 /// <param name="openFlags">A bit-mask of <code>FileOpenFlags</code> values.</param>
 /// <returns>Error code</returns>
 public PPError Open(FileRef fileRef, FileOpenFlags openFlags)
 => (PPError)PPBFileIO.Open(this, fileRef, (int)openFlags, new CompletionCallback(OnOpen));