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.6 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 long RegisterWorkerId(string ip, int port, string password, int maxWorkerIdNumber);
  25. //public static extern ulong RegisterWorkerId2();
  26. [DllImport("yitidgengo.dll", CallingConvention = CallingConvention.StdCall)]
  27. public static extern void UnRegisterWorkerId();
  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. txtIdList.Text += RegisterWorkerId(ip, 6379, "", 4) + "\r\n";
  44. //txtIdList.Text += RegisterWorkerId() + "\r\n";
  45. //txtIdList.Text += Test() + "\r\n";
  46. }
  47. catch (Exception ex)
  48. {
  49. txtIdList.Text = ex.Message;
  50. }
  51. }
  52. private void button1_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. UnRegisterWorkerId();
  57. txtIdList.Text += "LogOff";
  58. }
  59. catch (Exception ex)
  60. {
  61. txtIdList.Text = ex.Message;
  62. }
  63. // GetWorkerId("localhost", 6379);
  64. }
  65. }
  66. }

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