I have written the below code-snippet in Main method. I'm not able to use await keyword before WriteAsync().
snippet-1:
while (fileLength < 100)
            {
                i = i + 1;
                sampleText = String.Format("Line {0} of {1} \n", i, lineCount);
                data = encoding.GetBytes(sampleText);
                fileStream.WriteAsync(data, 0, data.Length);
                fileLength = fileLength + data.Length;
                Console.WriteLine("Length of file written: " + fileLength);
            }
 fileStream.Close();
snippet-2:
while (fileStream1.Position == fileLength)
            {
                 fileStream1.ReadAsync(data, 0, 100);
            }
The connection is closed in snippet-1 after the execution of while loop and snippet-2 is working fine.
while executing it I have got the following queries:
- Is it mandatory to  use await operator before WriteAsync(Byte[], Int32, Int32)?
- Can we use ReadAsync(Byte[], Int32, Int32)without any await operator?
- Can we use Thread.Sleepin place of await operator?
I have little experience in C# and multi-threading. Can any one help me in getting understand on the above queries?
 
     
    