using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace ESCARLETPrint { public class ESCARLETPrint { /// /// 电子发票网址打印 /// /// /// public string PrintESCARLETUrl(string input) { System.Diagnostics.Debugger.Launch(); String errorCode = "0"; String errorMessage = ""; JObject output = new JObject(); JArray fileStringArray = new JArray(); try { Thread thread; dynamic inputobj = Newtonsoft.Json.JsonConvert.DeserializeObject(input); var paramsobj = inputobj["params"][0]; thread = new Thread(() => Print()); thread.SetApartmentState(ApartmentState.STA); //重点 thread.Start(); thread.Join(); } catch (Exception ex) { errorMessage = ex.Message; } output.Add("errorCode", errorCode); output.Add("errorMessage", errorMessage); return output.ToString(); } private JObject Print() { JObject output = new JObject(); try { for (int i = 0; i < 50; i++) { Thread.Sleep(500); } } catch (Exception ex2) { } return output; } } }