This forum is meant for questions and discussions about the X# language and tools
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 9:01 am
Hi Nick,
thank you very much, I will try it.
But in the meantime I have tried something other and it seems to work:
Code: Select all
oThread := System.Threading.Thread{ { => self:_ConnectA( cHostName, cUserName, cPassword, nPort, oConfig ) } }
oThread:Start()
while oThread:IsAlive
System.Threading.Thread.Sleep( 10 )
end
Using this code my debug output shows the right sequence:
Code: Select all
Creating AsyncFtpClient
Creating Task Connect()
Awaiting Task Connect()
Task Connect() finished
Waited 00:00:00.2349512
Connected is True
Is there anything that makes this code dangerous?
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248 Joined: Fri Oct 14, 2016 7:09 am
Post
by NickFriend » Thu Mar 02, 2023 9:19 am
Hi Wolfgang,
To be honest I'm not entirely sure if there's a problem with the way you're doing it.... the only thing that occurs to me is that your code has no real means of error trapping, which is covered by the AsyncHelper class. Also it seems a bit ugly to use Sleep!
I've been using the helper class for years now without issue (though of course by definition it's use is very limited in our app).
Nick
HansjoergP
Posts: 141 Joined: Mon Jul 25, 2016 3:58 pm
Location: Italy
Post
by HansjoergP » Thu Mar 02, 2023 9:38 am
Hi Wolfgang,
why you don't use "oThread:Wait()"?
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 9:44 am
Hi Hansjörg,
why you don't use "oThread:Wait()"?
I don't have that method....
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 9:55 am
Hi Nick,
I'm now trying to translate that class to X#.
@Robert: I remember there was a discussion about how to translate the underscore to X#:
Code: Select all
synch.Post(async _ =>
{
try
{
await task();
}
catch (Exception e)
{
synch.InnerException = e;
throw;
}
finally
{
synch.EndMessageLoop();
}
}, null);
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248 Joined: Fri Oct 14, 2016 7:09 am
Post
by NickFriend » Thu Mar 02, 2023 10:05 am
Sorry, can't help you there... can't you just leave it in a class library to avoid the pain of translation?
Nick
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 10:29 am
Hi Nick,
as temporary solution it works as separate library, but to deliver it I need to translate it to X#.
But the good thing: it seems to work very well and simplifies my code a lot.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 10:31 am
Hi Hansjörg,
with Task.Run it does not works - the method does not permits that.
It works only with a Thread, with a Task it is not executed.
With Nicks class it works more elegantly.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Thu Mar 02, 2023 10:49 am
Hi Robert or Chris,
how do I translate this code from C# to X#?
It is the method from this class:
https://learn.microsoft.com/en-us/dotne ... work-4.8.1
When I write
Code: Select all
self:Post( { => self:done := true }, null )
the compiler says
Code: Select all
error XS1593: Delegate 'System.Threading.SendOrPostCallback' does not take 0 arguments
Thank you very much for any hint!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it