I am facing some problem when try to run multiple methods simultaneously with some sort of priority. Below is my code:
public static void Main(string[]args)
{
List<string> keyList = new List<string>();
var connecttask = Task.Factory.StartNew(() => getkeyword(0)).ContinueWith(prevTask => connect(1000, keyList));
}
The getkeyword() method must run first because it has to pass a List parameters to connect() method in order to let connect() method to perform its task.
However, this code will not run unless I insert some Console.WriteLine under the code, for example:
public static void Main(string[]args)
{
List<string> keyList = new List<string>();
var connecttask = Task.Factory.StartNew(() => getkeyword(0)).ContinueWith(prevTask => connect(1000, keyList));
Console.WriteLine("Connecting...");
Console.ReadLine();
}
Why does this happen? I do not want the Console.WriteLine or even Console.ReadLine take in place here because this is the code that I'm going to implement behind a UI button. Is there any way to solve this or any other method to run multiple method simultaneously but with a priority?
Thanks.