/// <summary> /// Convert the text from the image to strings /// Translate those strings to the desired language /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonTranslate_Click(object sender, EventArgs e) { try { //Define the tools being used for detection and translation string res = ""; OCR convert = new OCR(); Translation tr = new Translation(); Task.Run(async() => { //Wait for the API to respond res = await convert.ConvertToText(filePath); }).Wait(); textBoxDetected.Text = res; //Display the detected characters textBoxDetected.ReadOnly = true; //lock the text box //Define the selected language and detected characters as a pair KeyValuePair <string, string> vp = new KeyValuePair <string, string>(res, langCodes[langCode]); Task.Run(async() => { //Wait for the translation res = await tr.TranslateText(vp); }).Wait(); textBoxTranslated.Text = res; //Display the translated text textBoxTranslated.ReadOnly = true; //lock the text box } catch (Exception ex) { ErrorLogger.Log(LogLevel.Info, e); //Log exception MessageBox.Show(ex.Message); } }