public static async Task <SavesClass> UploadFilesAsync(string PathFileToUpload, string Username, ProgressBar PB, Label LBL) { string Filename = Path.GetFileName(PathFileToUpload); string DLink, FileSize; try { using (MALogin MAL = new MALogin()) { MegaApiClient client = MAL.Login(); INode Folder = await Task.Run(() => ChkIfFolderAndFileExist(client, Username, Filename)); if (Folder != null) { Progress <double> ze = new Progress <double>(p => PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg((int)p, PB, LBL); }))); using (FileStream stream = File.Open(@PathFileToUpload, FileMode.Open)) { INode FileUploaded = await client.UploadAsync(stream, Filename, Folder, ze); //Uploading File from PC to Mega //INode FileUploaded = await client.UploadFileAsync(PathFileToUpload, Folder, ze); //Uploading File from PC to Mega if (FileUploaded != null) { DLink = (await client.GetDownloadLinkAsync(FileUploaded)).ToString(); FileSize = (((int)(FileUploaded.Size / 1024))).ToString(); //Size in Kb client.Logout(); GC.Collect(); // TENGO QUE LLAMAR ESTO O NO DEJA BORRAR EL ARCHIVO ZIP PORQUE DICE QUE AUN ESTA EN USO. if (!DLink.Equals("")) { SavesClass SC = new SavesClass(); SC.DLink = DLink; SC.Size = FileSize; return(SC); } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } } catch { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(102, PB, LBL); })); return(null); } }