0

I am using dropbox api in my winforms app for the picture upload . I want that when picture upload unsuccessful then it auto retry after 2 second to upload it . This method call after every 2 minutes and i want if upload is unsuccessful then it will retry to upload it.

       static string token = "ABC";

    async Task Uploaded()
      {

        using (var dbx = new DropboxClient(token))

        {


            bmp = new Bitmap(picboxcapture.Image);
           
            string folder = "/pic/" + Login.recuser + "";
            string filename = DateTime.Now.ToString() + " " + "  " + MyTodo_Project.rectsk + ".JPG";
            string URL = picboxcapture.Image.ToString();

            ImageConverter converter = new ImageConverter();
        

            byte[] bytes = (byte[])converter.ConvertTo(picboxcapture.Image, typeof(byte[]));
            var mem = new MemoryStream(bytes);

          
            var updated = dbx.Files.UploadAsync(folder + "/" + filename, 
            WriteMode.Overwrite.Instance, body: mem);
            updated.Wait();
            var tx = dbx.Sharing.CreateSharedLinkWithSettingsAsync(folder + "/" + filename);
            tx.Wait();
            URL = tx.Result.Url;
         

            

          
        }


    }



        private async void save_Load(object sender, EventArgs e)
         {
       

            await Uploaded();
         }
  • You need to remove `updated.Wait();` and `tx.Wait();` and await those methods instead. Evaluate the result and `await Task.Delay(2000)` if you're not happy with it and you want to retry. You also need to show the code that calls `async Task Uploaded()` and the context in which this method is called (an event handler, another method body etc.). – Jimi Oct 05 '20 at 08:15
  • If the goal is to have a try/retry logic then this SO answer - https://stackoverflow.com/a/1563234 – kshkarin Oct 05 '20 at 08:20

0 Answers0