Welcome, Guest
Username: Password: Remember me

TOPIC:

Async question 02 Mar 2023 12:00 #25501

  • robert
  • robert's Avatar


  • Posts: 3600
  • Wolfgang,
    We also accept the discard name '_' in our code.
    Did you try
    self:Post( { _ => self:done := true }, null )

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Async question 02 Mar 2023 12:13 #25502

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3366
  • Hi Robert,
    ok, thank you very much, that works.
    But how do I add an async keyword to a lamda expression?
    synch.Post(async _ =>
                {
                    try
                    {
                        await task();
                    }
                    catch (Exception e)
                    {
                        synch.InnerException = e;
                        throw;
                    }
                    finally
                    {
                        synch.EndMessageLoop();
                    }
                }, null);
    does not works as
    synch:Post( { _ =>
    	    try
            await task()
    	    catch e as Exception
            synch.InnerException := e
            throw
    	    finally
            synch:EndMessageLoop()
    	    end try
    	}, null )
    and adding the async before the underscore like
    synch:Post( { async _ =>
    	    try
    gives
    error XS9002: Parser: unexpected input '_'
    Thank you again!
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Async question 02 Mar 2023 14:06 #25504

    • robert
    • robert's Avatar


  • Posts: 3600
  • Wolfgang,

    Change the lambda to a delegate
    synch:Post(  async delegate(_ as object)  { 
    	try
               await task()
    	catch e as Exception
                synch.InnerException := e
                 throw
    	finally
                synch:EndMessageLoop()
    	 end try
    	}, null )

    Note I did not test this since I do not have all the code

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Async question 02 Mar 2023 20:19 #25510

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3366
  • Hi Robert,
    thank you very much, my code compiles now without error.And it works also <g>.I have attached the entire prg file here if someone other needs it:

    File Attachment:

    File Name: AsyncHelpers.zip
    File Size:1 KB

    Thank you very much for all your assistance!
    When my FTPS lib is ready, I will post a link to the sources here.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.