public static ImageLoadResponse SendLoadImageMultipartRequest(ImageApi apiInstance, int workerNumber, string inputFilePath, string fileName, Stream fileStream, ContentEncoding contentEncoding, OperationsManager.ProgressDelegate uploadOperationStartEventHandler) { Exception e = null; int pausems = 5000; for (int i = 0; i < FrameworkGlobals.MAX_RETRYING_REQUESTS; i++) { uploadOperationStartEventHandler.Invoke(workerNumber, inputFilePath, i); try { fileStream.Seek(0, SeekOrigin.Begin); ImageLoadResponse response = apiInstance.ImageLoadMultipart(fileStream, new LoadImageParameters() { ContentEncoding = contentEncoding, FileName = fileName }); return(response); } catch (Exception ex) { if (i < FrameworkGlobals.MAX_RETRYING_REQUESTS - 1) { Thread.Sleep(pausems); //marking a pause in case of cnx temporarily out and to avoid overhead. pausems += 2000; } else {//last iteration e = ex; } } } throw e; }