RdFakeSocket.cs 759 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Threading;
  3. using Ragdoll;
  4. using UnityEngine;
  5. namespace HttpApi
  6. {
  7. public class RdFakeSocket : ScriptSingleton<RdFakeSocket>
  8. {
  9. private const int SleepTime = 2000;
  10. private Thread _thread;
  11. private volatile bool _workerRunning = false;
  12. public void Start()
  13. {
  14. _workerRunning = true;
  15. _thread = new Thread(Worker);
  16. _thread.Start();
  17. }
  18. private async void Worker()
  19. {
  20. while (_workerRunning)
  21. {
  22. Thread.Sleep(SleepTime);
  23. var response = await Api.RefreshMsgList();
  24. }
  25. }
  26. public void Stop()
  27. {
  28. _workerRunning = false;
  29. }
  30. }
  31. }