You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to Avalonia, so I'm reading the codes here to learn.
However my C# experience tells me that all the async void in this project are not following best practices (hence, got all the problems described in the linked article).
Inside every async void function must to be wrapped with try catch, because if something crash in a async void function
then (1) the whole application would crashed (while we should pop up an error instead)
and (2) outside the async void function You cannot catch the error happening inside and so did not know what happened!
The async void function should be minimalist so that the main codes would be testable.
//this "async void" is not testableprivateasyncvoidDoSearch(strings){try{awaitDoSearchAsync(s);}catch(Exceptionex){Console.WriteLine(ex);// or send out a "signal" to pop up an error message with all the details of the error}}//but the important codes here are testablepublicasyncTaskDoSearchAsync(strings){IsBusy=true;try{
...}finally{IsBusy=false;}}
//this "async void" is not testableprivateasyncvoidLoadAlbums(){try{awaitLoadAlbumsAsync();}catch(Exceptionex){Console.WriteLine(ex);// or send out a "signal" to pop up an error message with all the details of the error}}//but the important codes here are testablepublicasyncTaskLoadAlbumsAsync(){
...}
I guess you didn't follow best practices for the sake of simplicity. But as you can see, the codes are not become more complex by following the best pratices. Besides it might inspire other peoples to make more robust applications.
The text was updated successfully, but these errors were encountered:
Hello,
I'm new to Avalonia, so I'm reading the codes here to learn.
However my C# experience tells me that all the
async void
in this project are not following best practices (hence, got all the problems described in the linked article).async void function
must to be wrapped with try catch, because if something crash in aasync void function
async void function
You cannot catch the error happening inside and so did not know what happened!async void function
should be minimalist so that the main codes would be testable.For eg: I would refactor this
async void DoSearch(string s)
as followingSimilar, this
async void LoadAlbums()
should be refactored as following:I guess you didn't follow best practices for the sake of simplicity. But as you can see, the codes are not become more complex by following the best pratices. Besides it might inspire other peoples to make more robust applications.
The text was updated successfully, but these errors were encountered: