I think it's pretty obvious in the title ; I want to copy a file without waiting for the result.
Functionaly I want this :
static void Main(string[] args)
{
string strCmdText = @"/C xcopy c:\users\florian\desktop\mytestfile.fil p:\";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Console.WriteLine("Finished !");
}
Basically my main thread is released after few milliseconds. I try to do like this :
static void Main(string[] args)
{
var t = Task.Run(() => Copy(@"c:\Users\florian\Desktop\mytestfile.fil", "p:"));
}
private static void Copy(string source, string destination)
{
using (FileStream SourceStream = File.Open(source, FileMode.Open))
{
using (FileStream DestinationStream = File.Create(destination + source.Substring(source.LastIndexOf('\\'))))
{
SourceStream.CopyToAsync(DestinationStream);
}
}
}
My mytestfile.fil is created in my destination folder but its size is 0kb.
Regards,