MicrothreadSample.txt 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //MRM:C#
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using OpenSim.Region.OptionalModules.Scripting.Minimodule;
  5. namespace OpenSim
  6. {
  7. class MiniModule : MRMBase
  8. {
  9. public microthreaded void MicroThreadFunction(string testparam)
  10. {
  11. Host.Object.Say("Hello " + testparam);
  12. relax; // the 'relax' keyword gives up processing time.
  13. // and should be inserted before, after or in
  14. // any computationally "heavy" zones.
  15. int c = 500;
  16. while(c-- < 0) {
  17. Host.Object.Say("C=" + c);
  18. relax; // Putting 'relax' in microthreaded loops
  19. // is an easy way to lower the CPU tax
  20. // on your script.
  21. }
  22. }
  23. public override void Start()
  24. {
  25. Host.Microthreads.Run(
  26. MicroThreadFunction("World!")
  27. );
  28. }
  29. public override void Stop()
  30. {
  31. }
  32. }
  33. }