0

I'm having an issue with a program I'm working on... I have a listener for the webengines worker state, so that when state = SUCCEEDED it will carry on with the rest of the code.

The problem is that the website I'm loading has a lot of ads and takes a few minutes for the state to finally reach "SUCCEEDED".

I plan on using a timer, but the only way to trigger the listener is if the state changes, is there any way I could manually change the webengines worker state?

something like:

webEngine.getLoadWorker().getState() = Worker.State.SUCCEEDED;

This code obviously doesn't work, but you get the point.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
user3513071
  • 161
  • 1
  • 3
  • 10

1 Answers1

1
is there any way I could manually change the webengines worker state

No. The state represents the state of the worker thread that is loading the page. It only changes to SUCCEEDED when the web page has (successfully) completed loading.

If you don't need the page to be fully loaded in order to execute the code that you want to execute, then it doesn't make sense to use a listener on the worker state to trigger the code (or, at least, not one that waits for the SUCCEEDED state). To answer your question, you need to determine the logic behind when you want your code to be executed. If it's not needing to be executed when the page is completely loaded, when do you want it to be executed?

Or, to ask the same thing another way, perhaps: under what circumstances do you intend to change the state of the load worker to SUCCEEDED? Why not just execute whatever code you are intending to execute then instead?

James_D
  • 201,275
  • 16
  • 291
  • 322
  • I understand your point. My program is very dependent on these listeners (I have 3 or 4 of them) so that when a webpage is loaded through the webengine, certain functions will follow, I don't see much of a way around having these listeners. Thanks for the help though, much appreciated. – user3513071 May 29 '14 at 01:58
  • I suppose maybe I could use the listener and when state = running I could then create a timer that will then execute the code after a certain amount of time, but I feel like this may be buggy. – user3513071 May 29 '14 at 02:00