ESCARLETPrint.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace ESCARLETPrint
  8. {
  9. public class ESCARLETPrint
  10. {
  11. /// <summary>
  12. /// 电子发票网址打印
  13. /// </summary>
  14. /// <param name="input"></param>
  15. /// <returns></returns>
  16. public string PrintESCARLETUrl(string input)
  17. {
  18. System.Diagnostics.Debugger.Launch();
  19. String errorCode = "0";
  20. String errorMessage = "";
  21. JObject output = new JObject();
  22. JArray fileStringArray = new JArray();
  23. try
  24. {
  25. Thread thread;
  26. dynamic inputobj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(input);
  27. var paramsobj = inputobj["params"][0];
  28. thread = new Thread(() => Print());
  29. thread.SetApartmentState(ApartmentState.STA); //重点
  30. thread.Start();
  31. thread.Join();
  32. }
  33. catch (Exception ex)
  34. {
  35. errorMessage = ex.Message;
  36. }
  37. output.Add("errorCode", errorCode);
  38. output.Add("errorMessage", errorMessage);
  39. return output.ToString();
  40. }
  41. private JObject Print()
  42. {
  43. JObject output = new JObject();
  44. try
  45. {
  46. for (int i = 0; i < 50; i++)
  47. {
  48. Thread.Sleep(500);
  49. }
  50. }
  51. catch (Exception ex2)
  52. {
  53. }
  54. return output;
  55. }
  56. }
  57. }