WebGadget busy state problem unsolvable?

Just starting out? Need help? Post your questions and find answers here.
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

WebGadget busy state problem unsolvable?

Post by ultralazor »

I've searched a lot, and nobody seems to be able to rememdy the ready-state issue with WebGadget. Even in other compilers that use it. Hoping some pros can help.

examples:
#PB_Web_Busy:breaks(stays 1) with certain(non-looping) jscript and maybe other stuff.

#PB_Web_StatusMessage:usually "Done"+#PB_Web_Busy=0 or ""+#PB_Web_Busy=0 but affected by jscript issue and localization(language)

You'll either end up in an infinite loop, crashing your app with exceptions, or not process a page correctly depending on how your code is laid out. No solutions seem to be available to date.

The safest thing I've found so far by analyzing a lot of loads in debugger:

Code: Select all

;breaks on slow connections likely, and with certain jscript
    Repeat
      If WaitWindowEvent(1000)=#PB_Event_Gadget
        If EventGadget()=#web
          If GetGadgetAttribute(#web,#PB_Web_Busy)=0
            thread=CreateThread(@timeout(),5000);delay() inside
            While IsThread(thread)
              WaitWindowEvent(1000)
            Wend
            Break
          EndIf
        EndIf
      EndIf
    ForEver
thanks
so many ideas so little time..
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: WebGadget busy state problem unsolvable?

Post by MachineCode »

#PB_Web_Busy with GetGadgetAttribute() definitely needs a timeout added for it. Team, you hear? :)

Here's how my own apps have been getting around it for the time being. It loads a web page and waits for a maximum of 60 seconds before giving up. Usually the web page will load much sooner than 60 seconds, but without a timeout, some websites will just loop forever, as you and I have discovered. :(

Side-note: Can someone tell me if I need to do the Delay(1) part? That is, will GetGadgetAttribute still return valid values if I'm not checking WindowEvents during the Repeat/Until loop? Thanks!

Code: Select all

SetGadgetText(#WebGad,URL$) ; Start loading a website into the WebGadget.
timeout=GetTickCount_()+60000 ; And wait up to 60 secs for it to be ready.

Repeat
  If WindowEvent()=0
    Delay(1)
  EndIf
  If GetGadgetAttribute(#WebGad,#PB_Web_Busy)=0
    Break
  EndIf
Until GetTickCount_()>timeout
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: WebGadget busy state problem unsolvable?

Post by ultralazor »

Yeah I use a 20 second one in another thread to keep from pausing the thread, cause webgadget seems to use the same thread as your program. A separate thread delay like I use and some form of check is probably the best. Question is what to check, busy state and status messages are completely unreliable with distributed programs..the page downloaded state fires way before busy state and status=Done a lot of the times too.

The reason I say this is unsolvable, is because people here and elsewhere known for their knowledge of the internals of this compiler and NT API can't 'solve' it. I doubt we'll get any official response or solution because of this.

EDIT: Here is Freak's code that also breaks under most uses:

Code: Select all

    While GetGadgetAttribute(10, #PB_Web_Busy)
      While WaitWindowEvent(1): Wend
    Wend
Looks like all the best coders here have been unable to get around it.
so many ideas so little time..
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: WebGadget busy state problem unsolvable?

Post by MachineCode »

My version works fine without a thread. Or is your problem different? I was just assuming it's the same.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: WebGadget busy state problem unsolvable?

Post by ultralazor »

MachineCode wrote:My version works fine without a thread. Or is your problem different? I was just assuming it's the same.

I only tested it once, using a delay in the thread the webgadget was loading in froze it.

Here is the best solution I can come up with. Adjust timeout based on potential load/connection:

Code: Select all

        thread=CreateThread(@timeout(),30000)
        While IsThread(thread)
          WaitWindowEvent(1000)
        Wend
        If GetGadgetAttribute(#web,#PB_Web_Busy) : SetGadgetState(#web,#PB_Web_Stop) : EndIf
Plugins like Flash and Java and ActiveX I think go in a separate thread but keep the control busy. I've had it return mixed results with busy state based around injected jscript(javascript).
so many ideas so little time..
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: WebGadget busy state problem unsolvable?

Post by MachineCode »

ultralazor wrote:I only tested it once, using a delay in the thread the webgadget was loading in froze it.
Perhaps you can post your code and an URL that causes it to freeze, so I can look at it more closely?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: WebGadget busy state problem unsolvable?

Post by ultralazor »

MachineCode wrote:
ultralazor wrote:I only tested it once, using a delay in the thread the webgadget was loading in froze it.
Perhaps you can post your code and an URL that causes it to freeze, so I can look at it more closely?

Any site, just make a window with a webgadget and button that triggers a big delay while it's busy.

I also found another big problem with webgadget, it completely ignores a lot of meta tags and headers. Especially No-Cache which breaks a lot of sites, especially session based flash ones. I'm not going to even try to hack something together for it, I know you have to use that nasty cache structure and the First-Next-Delete cache API calls with PeekS and pointers.
so many ideas so little time..
Post Reply