Form1.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using DotNettyFrom.common;
  12. using DotNettyFrom.netty;
  13. namespace DotNettyFrom
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. private NettyClient nc;
  22. private Thread t;
  23. private void BtnConnection_Click(object sender, EventArgs e)
  24. {
  25. /* var producer = Task.Factory.StartNew(() =>
  26. {
  27. for (int count = 0; count < 1000; count++)
  28. {
  29. }
  30. // blockingCollection.CompleteAdding();
  31. });*/
  32. nc = new NettyClient();
  33. t = new Thread(() => { nc.StartNetty("127.0.0.1", 4001); });
  34. t.Start();
  35. }
  36. private void Form1_Load(object sender, EventArgs e)
  37. {
  38. var consumer = Task.Factory.StartNew(() =>
  39. {
  40. foreach (UIInfoModel value in DataModel.ReceCollection.GetConsumingEnumerable())
  41. {
  42. Invoke(new ThreadStart(delegate { listBox1.Items.Add(value); }));
  43. }
  44. });
  45. }
  46. private void BtnDisConn_Click(object sender, EventArgs e)
  47. {
  48. nc.StopNetty();
  49. t.Abort();
  50. }
  51. private void BtnSendData_Click(object sender, EventArgs e)
  52. {
  53. nc.SendData("");
  54. }
  55. }
  56. }