Hi,
I have two async function one is iterative and another one is recursive. Both are performing very heavy task. Fallowing are both function. Both function I was calling from a third function one after another. First i was calling WritePST() after that AddDirectory(). But both are executing parallel. How can I force WritePST() function to wait until its do not completes its execution and then AddDirectory() should start its execution.
public async void XYZ()
{
................
....................
WritePST(mbxPath);
AddDirectory(folder, sDir)
}
public async void WritePST(string mbxPath)
{
if (!string.IsNullOrEmpty(mbxPath))
{
if ((attr & FileAttributes.Directory) == FileAttributes.Directory){
}
else{
//Doing Some Work.......
while(message != null)
{
await Task.delay(2);
progressBar.DoubleValue += 1;
//Doing Some Work.......
}
var dir = new DirectoryInfo(delPath);
dir.Attributes = dir.Attributes & ~FileAttributes.ReadOnly;
dir.Delete(true);
}
}
}
private async void AddDirectory(FolderInfo folder, string sDir)
{
try{
foreach (string f in Directory.GetFiles(sDir, "*.eml"))
{
await Task.delay(2);
progressBar.DoubleValue += 1;
MailMessage eml = MailMessage.Load(f);
folder.AddMessage(MapiMessage.FromMailMessage(eml));
}
foreach (string d in Directory.GetDirectories(sDir))
{
FolderInfo fi = folder.AddSubFolder(new DirectoryInfo(d).Name);
AddDirectoryT(fi, d);
}
}
catch (System.Exception excpt){
Console.WriteLine(excpt.Message);
}
}