You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

StartForm.cs 2.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace WInFormApp
  12. {
  13. public partial class StartForm : Form
  14. {
  15. public StartForm()
  16. {
  17. InitializeComponent();
  18. }
  19. [DllImport("yitidgengo.dll", CallingConvention = CallingConvention.StdCall)]
  20. public static extern long NextId();
  21. [DllImport("yitidgengo.dll", CallingConvention = CallingConvention.StdCall)]
  22. public static extern long NextId2();
  23. [DllImport("yitidgengo.dll", CallingConvention = CallingConvention.StdCall)]
  24. public static extern IntPtr RegisterMany(string ip, int port, string password, int maxWorkerIdNumber, int idCount);
  25. //public static extern ulong RegisterWorkerId2();
  26. [DllImport("yitidgengo.dll", CallingConvention = CallingConvention.StdCall)]
  27. public static extern void UnRegister();
  28. [DllImport("yitidgen.dll", CallingConvention = CallingConvention.StdCall)]
  29. public static extern void SetWorkerId(uint workerId);
  30. [DllImport("yitidgen.dll", CallingConvention = CallingConvention.StdCall)]
  31. public static extern int Test();
  32. [DllImport("yitidgen.dll", CallingConvention = CallingConvention.StdCall)]
  33. public static extern int GetWorkerId(string ip, int port);
  34. private void Form1_Load(object sender, EventArgs e)
  35. {
  36. }
  37. private void btnGen_Click(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. var ip = "localhost";
  42. //txtIdList.Text += RegisterWorkerId(Encoding.UTF8.GetBytes(ip), 6379) + "\r\n";
  43. var ids = RegisterMany(ip, 6379, "", 4, 3);
  44. //foreach (var id in ids)
  45. //{
  46. // txtIdList.Text += id;
  47. //}
  48. //txtIdList.Text += RegisterWorkerId() + "\r\n";
  49. //txtIdList.Text += Test() + "\r\n";
  50. }
  51. catch (Exception ex)
  52. {
  53. txtIdList.Text = ex.Message;
  54. }
  55. }
  56. private void button1_Click(object sender, EventArgs e)
  57. {
  58. try
  59. {
  60. UnRegister();
  61. txtIdList.Text += "LogOff";
  62. }
  63. catch (Exception ex)
  64. {
  65. txtIdList.Text = ex.Message;
  66. }
  67. // GetWorkerId("localhost", 6379);
  68. }
  69. }
  70. }

雪花算法中非常好用的数字ID生成器