MyWindowsService 录音批量下载服务源代码 vs2017 - 思念食品

Program.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace WindowsServiceClient
  10. {
  11. static class Program
  12. {
  13. /// <summary>
  14. /// 应用程序的主入口点。
  15. /// </summary>
  16. [STAThread]
  17. static void Main()
  18. {
  19. Start();
  20. Application.EnableVisualStyles();
  21. Application.SetCompatibleTextRenderingDefault(false);
  22. Application.Run(new Form1());
  23. }
  24. private static void Start()
  25. {
  26. HttpListener httpListenner;
  27. httpListenner = new HttpListener();
  28. httpListenner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
  29. httpListenner.Prefixes.Add("http://localhost:4033/");
  30. httpListenner.Start();
  31. new Thread(new ThreadStart(delegate {
  32. try
  33. {
  34. loop(httpListenner);
  35. httpListenner.Stop();
  36. }
  37. catch (Exception ex)
  38. {
  39. var ddd = ex.Message;
  40. httpListenner.Stop();
  41. }
  42. })).Start();
  43. }
  44. private static void loop(HttpListener httpListenner)
  45. {
  46. while (true)
  47. {
  48. HttpListenerContext context = httpListenner.GetContext();
  49. HttpListenerRequest request = context.Request;
  50. HttpListenerResponse response = context.Response;
  51. Servlet servlet = new MyServlet();
  52. servlet.onCreate();
  53. if (request.HttpMethod == "POST")
  54. {
  55. servlet.onPost(request, response);
  56. }
  57. else if (request.HttpMethod == "GET")
  58. {
  59. servlet.onGet(request, response);
  60. }
  61. response.Close();
  62. }
  63. }
  64. }
  65. }