Пример #1
0
        public async Task <bool> DoItInAsyncInNewThread(InfoObject info, bool configureAwait = true)
        {
            string currentMethodName = nameof(DoItInAsyncInNewThread);

            info.IncreaseIndentationLevel();
            var lenghtyStuff = new LengthyStuff();

            info.Log($"Begin of {currentMethodName} before DoLengthy-Async");
            var task = Task.Run(async() => await lenghtyStuff.DoLengthyOperationAsync(info, configureAwait)).ConfigureAwait(configureAwait);

            info.Log($"In {currentMethodName} after DoLengthy, but before await");
            bool result = await task;

            info.Log($"End of {currentMethodName} after awaiting of DoLengthy-Async");

            info.DecreaseIndentationLevel();
            return(result);
        }
Пример #2
0
        public async Task <bool> DoItInAsync(InfoObject info, bool configureAwait = true)
        {
            string currentMethodName = nameof(DoItInAsync);

            info.IncreaseIndentationLevel();
            var lenghtyStuff = new LengthyStuff();

            info.Log($"Begin of {currentMethodName} before calling DoLengthy-Async");
            var task = lenghtyStuff.DoLengthyOperationAsync(info, configureAwait).ConfigureAwait(continueOnCapturedContext: configureAwait);

            // perhaps you can do something before you need result from async-method
            info.Log($"In {currentMethodName} after calling DoLengthy-Async, but before awaiting it...");

            // but now need result form task
            bool result = await task;

            info.Log($"End of {currentMethodName} after awaiting DoLengthy-Async...");
            info.DecreaseIndentationLevel();

            return(result);
        }