I am trying to create an application for learning purposes going along with an Async in C# book. However I am having trouble implementing the ideas in the form of which i want. Please let me know if this is doable or not.
Basically, I have a console application with 3 classes. The user inputs some data on the console and then I have a class which executes a SQL command/query and creates a datatable. However the queries actually take quite a bit of time depending on the time of day so this is what I Want: I want to run the class/function which executes my sql query, executes some code right below it in the main program, and then wait for the sql query/data table to finish. After this I then do an export to excel. A portion of the code is below, but what I am having trouble with is the syntax for the async command. I tried making a task which indicates the calling of the sql query function but i get a compiler error saying it cannot convert the type into a task. Is there a way to do this by assigning my createReport function as a task and then awaiting for it to complete later on?
if (Regex.IsMatch(Number,@"^\d+$") && Number.Length <= 3)
{
reportCreate.createReport(detailLength,detailDate,detailNumber);
/* ^^ This was my original syntax but I want to make this asynchronous or in
a separate thread so I can continue working below.*/
// do some comparing work here while the sql query/datatable is running.
/* Wait for the datatable thread to finish and then continue with the code
below. Is there a way to do this using task and await? */
}