public void TranslateAsync(string input, string sourceLanguage, string targetLanguage, TranslateTextCallBack callBack) { if (string.IsNullOrWhiteSpace(input)) throw new ArgumentNullException("input"); if (string.IsNullOrWhiteSpace(sourceLanguage)) throw new ArgumentNullException("sourceLanguage"); if (string.IsNullOrWhiteSpace(targetLanguage)) throw new ArgumentNullException("targetLanguage"); if (callBack == null) throw new ArgumentNullException("callBack"); System.Globalization.CultureInfo targetCulture = System.Globalization.CultureInfo.GetCultureInfo(targetLanguage); System.Globalization.CultureInfo sourceCulture = System.Globalization.CultureInfo.GetCultureInfo(targetLanguage); this.TranslateAsync(input, this.SourceCulture, targetCulture, callBack); }
public void TranslateAsync(string input, System.Globalization.CultureInfo sourceCulture, System.Globalization.CultureInfo targetCulture, TranslateTextCallBack callBack) { if (string.IsNullOrWhiteSpace(input)) throw new ArgumentNullException("input"); if (sourceCulture == null) throw new ArgumentNullException("sourceCulture"); if (targetCulture == null) throw new ArgumentNullException("targetCulture"); if (callBack == null) throw new ArgumentNullException("callBack"); TranslateDetails translationDetails = this.CreateTranslateDetails(input, sourceCulture, targetCulture); System.Threading.ThreadPool.QueueUserWorkItem(a=>{ try { this.SetTranslationDetails(translationDetails, this.Translate(input, sourceCulture, targetCulture)); } catch (Exception ex) { this.SetTranslationDetails(translationDetails, ex); } finally { callBack.Invoke(translationDetails); } }); }