Skip to main content
added 254 characters in body
Source Link
svick
  • 24.3k
  • 4
  • 52
  • 89

To follow the Task-based Asynchronous Pattern and usual naming conventions (methods should be verbs, not nouns), your Authentication method should be named something like AuthenticateAsync.

 

Also, ifIf this was a real code, you shouldn't use Task.Run() on a synchronous method, instead the whole CheckIfNameExistsInDatabaseOnServer method should be asynchronous, since accessing the DB is IO-bound.


The parentheses in your ternary expression are not necessary (also following Malachi's advice about newlines):

string outputString = await Authentication(usernameTextBox.Text)
    ? "Name exists" 
    : "Name does not exist";

To follow the Task-based Asynchronous Pattern and usual naming conventions (methods should be verbs, not nouns), your Authentication method should be named something like AuthenticateAsync.

Also, if this was a real code, you shouldn't use Task.Run() on a synchronous method, instead the whole CheckIfNameExistsInDatabaseOnServer method should be asynchronous, since accessing the DB is IO-bound.

To follow the Task-based Asynchronous Pattern and usual naming conventions (methods should be verbs, not nouns), your Authentication method should be named something like AuthenticateAsync.

 

If this was a real code, you shouldn't use Task.Run() on a synchronous method, instead the whole CheckIfNameExistsInDatabaseOnServer method should be asynchronous, since accessing the DB is IO-bound.


The parentheses in your ternary expression are not necessary (also following Malachi's advice about newlines):

string outputString = await Authentication(usernameTextBox.Text)
    ? "Name exists" 
    : "Name does not exist";
Source Link
svick
  • 24.3k
  • 4
  • 52
  • 89

To follow the Task-based Asynchronous Pattern and usual naming conventions (methods should be verbs, not nouns), your Authentication method should be named something like AuthenticateAsync.

Also, if this was a real code, you shouldn't use Task.Run() on a synchronous method, instead the whole CheckIfNameExistsInDatabaseOnServer method should be asynchronous, since accessing the DB is IO-bound.