Last active
January 10, 2020 06:24
-
-
Save cosminpopescu14/c5852d6e5de38366f847949d630171a9 to your computer and use it in GitHub Desktop.
Exploring async/await and linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Security; | |
using System.Security.Permissions; | |
using System.Threading.Tasks; | |
[assembly: CompilationRelaxations(8)] | |
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] | |
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] | |
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] | |
[assembly: AssemblyVersion("0.0.0.0")] | |
[module: UnverifiableCode] | |
namespace HelloWorld | |
{ | |
internal class Program | |
{ | |
[Serializable] | |
[CompilerGenerated] | |
private sealed class <>c | |
{ | |
public static readonly <>c <>9 = new <>c(); | |
public static Func<int, bool> <>9__0_0; | |
internal bool <Main>b__0_0(int score) | |
{ | |
return score > 80; | |
} | |
} | |
[CompilerGenerated] | |
private sealed class <SmthAsync>d__1 : IAsyncStateMachine | |
{ | |
public int <>1__state; | |
public AsyncTaskMethodBuilder<int> <>t__builder; | |
private TaskAwaiter <>u__1; | |
private void MoveNext() | |
{ | |
int num = <>1__state; | |
int result; | |
try | |
{ | |
TaskAwaiter awaiter; | |
if (num != 0) | |
{ | |
awaiter = Task.Delay(5000).GetAwaiter(); | |
if (!awaiter.IsCompleted) | |
{ | |
num = (<>1__state = 0); | |
<>u__1 = awaiter; | |
<SmthAsync>d__1 stateMachine = this; | |
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine); | |
return; | |
} | |
} | |
else | |
{ | |
awaiter = <>u__1; | |
<>u__1 = default(TaskAwaiter); | |
num = (<>1__state = -1); | |
} | |
awaiter.GetResult(); | |
Console.WriteLine("SmthAsync"); | |
result = 1; | |
} | |
catch (Exception exception) | |
{ | |
<>1__state = -2; | |
<>t__builder.SetException(exception); | |
return; | |
} | |
<>1__state = -2; | |
<>t__builder.SetResult(result); | |
} | |
void IAsyncStateMachine.MoveNext() | |
{ | |
//ILSpy generated this explicit interface implementation from .override directive in MoveNext | |
this.MoveNext(); | |
} | |
[DebuggerHidden] | |
private void SetStateMachine(IAsyncStateMachine stateMachine) | |
{ | |
} | |
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) | |
{ | |
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine | |
this.SetStateMachine(stateMachine); | |
} | |
} | |
private static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
Task<int> value = SmthAsync(); | |
Console.WriteLine(value); | |
int[] obj = new int[4]; | |
RuntimeHelpers.InitializeArray(obj, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); | |
int[] source = obj; | |
IEnumerable<int> enumerable = Enumerable.Where(source, <>c.<>9__0_0 ?? (<>c.<>9__0_0 = new Func<int, bool>(<>c.<>9.<Main>b__0_0))); | |
IEnumerator<int> enumerator = enumerable.GetEnumerator(); | |
try | |
{ | |
while (enumerator.MoveNext()) | |
{ | |
Console.Write(enumerator.Current.ToString() + " "); | |
} | |
} | |
finally | |
{ | |
if (enumerator != null) | |
{ | |
enumerator.Dispose(); | |
} | |
} | |
} | |
[AsyncStateMachine(typeof(<SmthAsync>d__1))] | |
[DebuggerStepThrough] | |
public static Task<int> SmthAsync() | |
{ | |
<SmthAsync>d__1 stateMachine = new <SmthAsync>d__1(); | |
stateMachine.<>t__builder = AsyncTaskMethodBuilder<int>.Create(); | |
stateMachine.<>1__state = -1; | |
AsyncTaskMethodBuilder<int> <>t__builder = stateMachine.<>t__builder; | |
<>t__builder.Start(ref stateMachine); | |
return stateMachine.<>t__builder.Task; | |
} | |
} | |
} | |
[CompilerGenerated] | |
internal sealed class <PrivateImplementationDetails> | |
{ | |
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 16)] | |
private struct __StaticArrayInitTypeSize=16 | |
{ | |
} | |
internal static readonly __StaticArrayInitTypeSize=16 2E7E3C3EED49854EC7DD37F9D3703E51733E99D7/* Not supported: data(61 00 00 00 5C 00 00 00 51 00 00 00 3C 00 00 00) */; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace HelloWorld | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
var res = SmthAsync(); | |
Console.WriteLine(res); | |
// Specify the data source. | |
int[] scores = new int[] { 97, 92, 81, 60 }; | |
// Define the query expression. | |
IEnumerable<int> scoreQuery = | |
from score in scores | |
where score > 80 | |
select score; | |
// Execute the query. | |
foreach (int i in scoreQuery) | |
{ | |
Console.Write(i + " "); | |
} | |
} | |
public static async Task<int> SmthAsync() | |
{ | |
await Task.Delay(5000); | |
Console.WriteLine("SmthAsync"); | |
return 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment