What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Out or Anyone who can answer: How do I cancel a method from continuing?

Status
Not open for further replies.

JoeBobJr

Member
Joined
Oct 25, 2014
Messages
151
Reaction score
0
I'm wanting to allow my plugin to have a check box on the widget. I want it to start when the checkbox is checked then stop when its unchecked. It works great when its checked it does what it suppose to do but when its unchecked it won't stop. Is there is way to cancel PlantItemsAsFarm or CollectItemsAtFarm? Here is the code I am using but I can't get it to stop once its started unless I turn the plugin off.

Code:
      public void PluginRun() {
            
            SetGroupStatus("Auto Farm", false);
            while (true)
            {
                if (GetGroupStatus("Auto Farm"))
                {
                    int laborPoints = me.laborPoints;
                            
                        Random random = new Random();
                        var ms = random.Next(24, 107) * 1000;
                        var s = ms / 1000;
                        
                        if (laborPoints > 2000)
                        {
                           CollectItemsAtFarm("Azalea", "Gathering: Spend 1 Labor to gather materials.", 32462);
                           PlantItemsAtFarm("Azalea Seed", 24553);
                            
                        } else {

                            PlantItemsAtFarm("Azalea Seed", 43246);
                            
                            Log("Labor under 2000, waiting to regen");
                        }
                        Thread.Sleep(ms);
               } else {
                    CancelSkill(); <<<<<<<< Trying to cancel here but not working >>>>>>>>>
               }
               Thread.Sleep(50);
          }
          Thread.Sleep(50);
    }
 
Hi, i won't go in details, but i would do this using a different Thread and Abort that Thread if needed, this way you have the power to stop the Thread regardless from what it is doing ( Be sure to do stuffs Thread Safe, in that Thread...look some tutorial on Multithreading). This Assure you that that Method is Stopped immediately (won't grant you at what stage of that method it stop, for that you need many other flow control.)

Alternative would be to assign a variable (a Bool maybe) and check if that bool if true, and if not, then Break, but this will not stop that method immediately, but only when it reach the bool check.

This are just few ideas, there are many other way, i just hope this give you a idea o where to look.

/Hat
 
Status
Not open for further replies.
Back
Top