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;
}
}
}
}









share|improve this question
























  • 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















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;
}
}
}
}









share|improve this question
























  • 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













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;
}
}
}
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 17:11









        Serge Semenov

        2,9011119




        2,9011119






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)