public void Invoke() { if (State == null) { return; } State.Complete(); State = null; }
/** * Common code when cancelling an async waiter. */ private AsyncWaiter CancelCommon(object _awaiterNode) { LinkedListNode <AsyncWaiter> awaiterNode = (LinkedListNode <AsyncWaiter>)_awaiterNode; AsyncAwaiter awaiter = awaiterNode.Value; lock (theLock) { if (!awaiter.done) { // Remove the async waiter from the waiters list, and mark it as completed asyncWaiters.Remove(awaiterNode); awaiter.done = true; return(awaiter); } } return(null); }
/// <summary> /// Writes the text to the specified file /// </summary> /// <param name="text">The text to write</param> /// <param name="path">The path of the file to write to</param> /// <param name="append">If true, writes the text to the end of the file, otherwise overrides any existing file</param> /// <returns></returns> public async Task WriteTextToFileAsync(string text, string path, bool append = false) { // TODO: Add exception catching // Normalize path path = NormalizePath(path); // Resolve to absolute path path = ResolvePath(path); // Lock the task await AsyncAwaiter.AwaitAsync(nameof(BaseFileManager) + path, async() => { // Run the synchronous file access as a new task await new BaseTaskManager().Run(() => { // Write the log message to file using (var fileStream = (TextWriter) new StreamWriter(File.Open(path, append ? FileMode.Append : FileMode.Create))) fileStream.Write(text); }); }); }
static void StartAsyncAwaitModel() { Task t = AsyncAwaiter.AsynchronousProcessing(); t.Wait(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfiguredAsyncAwaitable"/> struct. /// </summary> public ConfiguredAsyncAwaitable(IAsyncOperation op, bool continueOnCapturedContext) { _awaiter = new AsyncAwaiter(op, continueOnCapturedContext); }