Delay in executing action.run() method

102 views Asked by At

I have written a utils method, where I have to invoke the run method of a Action. But, I have to call this util method repeatedly with different parameters. The util method signature is

clickPullDownMenu(String ViewID, String MenuPath){
    Display.getDefault.syncexec(new Runnable(){
        public void run(){
            //few lines of code
            action.run();
        }));
    }
}

When I give a 'view id' and the 'Menu' to be clicked.

Example.

    clickPullDownMenu("view_ID", "import");
    //check whether the entry is imported.

After I invoke the save menu item, it takes sometime for the 'run' method to run. Hence, my code to check whether the import of data is completed, is failing.

But, when I debug the same, it is successfully working as I use step over for each step.

Is there a way to wait till the run() method is completely fully? I suspect that run() method in turn may invoke some Runnables.

1

There are 1 answers

1
Jon Sansoucie On

If you know about how long the run method is taking on average, you can just wait the upper limit of that average to be safe if it's not too terribly long like so:

    private static int TIME_OUT = 3000; // for 3 seconds
    new Handler().postDelayed(new Runnable()
    {
        @Override
        public void run()
        {
            // do your thing here
            finish();
        }
    }, TIME_OUT);

You would put that where your action.run() call is.