Async/await - any changes in .NET 4.6 or .NET Core?
up vote
1
down vote
favorite
Hi All,
I plan to develop a custom awaiter quite similar to one presented in this brilliant article:
http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx
In short, it allows serializing the state of an async method, to be deserialized and resumed at a later time.
My concern is that the implementation (for .NET 4.5) is based on a hack of accessing a private field m_stateMachine
of struct AsyncMethodBuilderCore
, which is an internal type in mscorlib.
I edited the question following @Peter's comment:
I wonder if anyone who installed .NET 4.6 or .NET Core (ASP.NET 5) previews and investigated async/await in those versions, saw any change in how the compiler generates the state machine behind async/await, compared to .NET 4.5?
Some background
I am exploring possibility of authoring long-running workflows (similar to those provided by Windows Workflow Foundation) using C# async/await syntax. Which means that in my case, async/await must be backed by persistence and tracking mechanisms. Then the code of a workflow would look like this:
public class ProcessingWorkflowOfForm12345C : AbstractWorkflow<Form12345C>
{
private readonly ExternalServices _services;
public ProcessingWorkflowOfForm12345C(ExternalServices services)
{
_services = services;
}
public override async void Run(Form12345C form)
{
while ( form.ExtraDocumentsRequired )
{
var extraDocuments = await _services.RequestExtraDocuments(
form.GetRequiredExtraDocuments()); // can take weeks
form.AddExtraDocuments(extraDocuments);
}
var approvalResult = _services.AutoApprove(form);
while ( true )
{
switch ( approvalResult )
{
case ApprovalResult.Approved:
form.SetApproved();
return;
case ApprovalResult.Rejected:
form.SetRejected();
return;
case ApprovalResult.Manual:
approvalResult =
await _services.RequestManualApproval(form); // can take days
break;
}
}
}
}
c# async-await
|
show 5 more comments
up vote
1
down vote
favorite
Hi All,
I plan to develop a custom awaiter quite similar to one presented in this brilliant article:
http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx
In short, it allows serializing the state of an async method, to be deserialized and resumed at a later time.
My concern is that the implementation (for .NET 4.5) is based on a hack of accessing a private field m_stateMachine
of struct AsyncMethodBuilderCore
, which is an internal type in mscorlib.
I edited the question following @Peter's comment:
I wonder if anyone who installed .NET 4.6 or .NET Core (ASP.NET 5) previews and investigated async/await in those versions, saw any change in how the compiler generates the state machine behind async/await, compared to .NET 4.5?
Some background
I am exploring possibility of authoring long-running workflows (similar to those provided by Windows Workflow Foundation) using C# async/await syntax. Which means that in my case, async/await must be backed by persistence and tracking mechanisms. Then the code of a workflow would look like this:
public class ProcessingWorkflowOfForm12345C : AbstractWorkflow<Form12345C>
{
private readonly ExternalServices _services;
public ProcessingWorkflowOfForm12345C(ExternalServices services)
{
_services = services;
}
public override async void Run(Form12345C form)
{
while ( form.ExtraDocumentsRequired )
{
var extraDocuments = await _services.RequestExtraDocuments(
form.GetRequiredExtraDocuments()); // can take weeks
form.AddExtraDocuments(extraDocuments);
}
var approvalResult = _services.AutoApprove(form);
while ( true )
{
switch ( approvalResult )
{
case ApprovalResult.Approved:
form.SetApproved();
return;
case ApprovalResult.Rejected:
form.SetRejected();
return;
case ApprovalResult.Manual:
approvalResult =
await _services.RequestManualApproval(form); // can take days
break;
}
}
}
}
c# async-await
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
1
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
5
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
1
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37
|
show 5 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Hi All,
I plan to develop a custom awaiter quite similar to one presented in this brilliant article:
http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx
In short, it allows serializing the state of an async method, to be deserialized and resumed at a later time.
My concern is that the implementation (for .NET 4.5) is based on a hack of accessing a private field m_stateMachine
of struct AsyncMethodBuilderCore
, which is an internal type in mscorlib.
I edited the question following @Peter's comment:
I wonder if anyone who installed .NET 4.6 or .NET Core (ASP.NET 5) previews and investigated async/await in those versions, saw any change in how the compiler generates the state machine behind async/await, compared to .NET 4.5?
Some background
I am exploring possibility of authoring long-running workflows (similar to those provided by Windows Workflow Foundation) using C# async/await syntax. Which means that in my case, async/await must be backed by persistence and tracking mechanisms. Then the code of a workflow would look like this:
public class ProcessingWorkflowOfForm12345C : AbstractWorkflow<Form12345C>
{
private readonly ExternalServices _services;
public ProcessingWorkflowOfForm12345C(ExternalServices services)
{
_services = services;
}
public override async void Run(Form12345C form)
{
while ( form.ExtraDocumentsRequired )
{
var extraDocuments = await _services.RequestExtraDocuments(
form.GetRequiredExtraDocuments()); // can take weeks
form.AddExtraDocuments(extraDocuments);
}
var approvalResult = _services.AutoApprove(form);
while ( true )
{
switch ( approvalResult )
{
case ApprovalResult.Approved:
form.SetApproved();
return;
case ApprovalResult.Rejected:
form.SetRejected();
return;
case ApprovalResult.Manual:
approvalResult =
await _services.RequestManualApproval(form); // can take days
break;
}
}
}
}
c# async-await
Hi All,
I plan to develop a custom awaiter quite similar to one presented in this brilliant article:
http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx
In short, it allows serializing the state of an async method, to be deserialized and resumed at a later time.
My concern is that the implementation (for .NET 4.5) is based on a hack of accessing a private field m_stateMachine
of struct AsyncMethodBuilderCore
, which is an internal type in mscorlib.
I edited the question following @Peter's comment:
I wonder if anyone who installed .NET 4.6 or .NET Core (ASP.NET 5) previews and investigated async/await in those versions, saw any change in how the compiler generates the state machine behind async/await, compared to .NET 4.5?
Some background
I am exploring possibility of authoring long-running workflows (similar to those provided by Windows Workflow Foundation) using C# async/await syntax. Which means that in my case, async/await must be backed by persistence and tracking mechanisms. Then the code of a workflow would look like this:
public class ProcessingWorkflowOfForm12345C : AbstractWorkflow<Form12345C>
{
private readonly ExternalServices _services;
public ProcessingWorkflowOfForm12345C(ExternalServices services)
{
_services = services;
}
public override async void Run(Form12345C form)
{
while ( form.ExtraDocumentsRequired )
{
var extraDocuments = await _services.RequestExtraDocuments(
form.GetRequiredExtraDocuments()); // can take weeks
form.AddExtraDocuments(extraDocuments);
}
var approvalResult = _services.AutoApprove(form);
while ( true )
{
switch ( approvalResult )
{
case ApprovalResult.Approved:
form.SetApproved();
return;
case ApprovalResult.Rejected:
form.SetRejected();
return;
case ApprovalResult.Manual:
approvalResult =
await _services.RequestManualApproval(form); // can take days
break;
}
}
}
}
c# async-await
c# async-await
edited Apr 12 '15 at 0:44
asked Apr 11 '15 at 19:02
felix-b
4,0071329
4,0071329
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
1
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
5
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
1
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37
|
show 5 more comments
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
1
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
5
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
1
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
1
1
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
5
5
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
1
1
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37
|
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
The state machine generator has not changed, it's still exactly the same. The only thing that changed starting with .NET Core 2.1 is the new type AsyncStateMachineBox
replaced MoveNextRunner
.
You can find source code that accesses fields of a state machine for serialization here:
https://github.com/Dasync/Dasync/tree/master/Engine/AsyncStateMachine
P.S. there are obvious benefits of using compiler-generated state machines for distributed computing. As of today, this can be viewed as a hack, perhaps tomorrow it comes as a built-in language support.
Conquest of Distributed Systems (part 4) — The Now and the Vision
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The state machine generator has not changed, it's still exactly the same. The only thing that changed starting with .NET Core 2.1 is the new type AsyncStateMachineBox
replaced MoveNextRunner
.
You can find source code that accesses fields of a state machine for serialization here:
https://github.com/Dasync/Dasync/tree/master/Engine/AsyncStateMachine
P.S. there are obvious benefits of using compiler-generated state machines for distributed computing. As of today, this can be viewed as a hack, perhaps tomorrow it comes as a built-in language support.
Conquest of Distributed Systems (part 4) — The Now and the Vision
add a comment |
up vote
0
down vote
The state machine generator has not changed, it's still exactly the same. The only thing that changed starting with .NET Core 2.1 is the new type AsyncStateMachineBox
replaced MoveNextRunner
.
You can find source code that accesses fields of a state machine for serialization here:
https://github.com/Dasync/Dasync/tree/master/Engine/AsyncStateMachine
P.S. there are obvious benefits of using compiler-generated state machines for distributed computing. As of today, this can be viewed as a hack, perhaps tomorrow it comes as a built-in language support.
Conquest of Distributed Systems (part 4) — The Now and the Vision
add a comment |
up vote
0
down vote
up vote
0
down vote
The state machine generator has not changed, it's still exactly the same. The only thing that changed starting with .NET Core 2.1 is the new type AsyncStateMachineBox
replaced MoveNextRunner
.
You can find source code that accesses fields of a state machine for serialization here:
https://github.com/Dasync/Dasync/tree/master/Engine/AsyncStateMachine
P.S. there are obvious benefits of using compiler-generated state machines for distributed computing. As of today, this can be viewed as a hack, perhaps tomorrow it comes as a built-in language support.
Conquest of Distributed Systems (part 4) — The Now and the Vision
The state machine generator has not changed, it's still exactly the same. The only thing that changed starting with .NET Core 2.1 is the new type AsyncStateMachineBox
replaced MoveNextRunner
.
You can find source code that accesses fields of a state machine for serialization here:
https://github.com/Dasync/Dasync/tree/master/Engine/AsyncStateMachine
P.S. there are obvious benefits of using compiler-generated state machines for distributed computing. As of today, this can be viewed as a hack, perhaps tomorrow it comes as a built-in language support.
Conquest of Distributed Systems (part 4) — The Now and the Vision
answered Nov 21 at 17:11
Serge Semenov
2,9011119
2,9011119
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29581864%2fasync-await-any-changes-in-net-4-6-or-net-core%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the advantage of using asynchrony in your flow? What are you trying to achieve?
– Yuval Itzchakov
Apr 11 '15 at 19:21
Microsoft knows but is not obliged to tell. It's your risk. To me at first sight it seems you are misusing the mechanism for something it wasn't designed for.
– Ondrej Tucny
Apr 11 '15 at 19:22
1
Side note: async-await does not need Tasks - you should consider creating your completely custom serializable Awaitable objects...
– Alexei Levenkov
Apr 11 '15 at 19:39
5
It might be just me, but i still cannot get my head around why you find serialization of the state machine appealing in any way, given it may change in any future release of the framework, causing your code to break. Not only that, but by also relying on it in your implementation would cause any future developer that might be the one fixing your code due to framework changes to have intimate knowledge of an implementation detail of the framework. I would run from that like burning fire.
– Yuval Itzchakov
Apr 11 '15 at 20:03
1
At best, the question is too broad. Also, any answer involves primarily speculation (a sort of opinion), and so is ill-suited to Stack Overflow.
– Peter Duniho
Apr 11 '15 at 23:37