Imediate Gadget Update

Just starting out? Need help? Post your questions and find answers here.
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

Imediate Gadget Update

Post by SniffTheGlove »

Hi,

I have a timing issue on clicking a ButtonGadget and disabling another ButtonGadget.

For simple means, I have a window with 2 Button Gadgets ("Connect A" and "Connect B"). When I click on one of the buttons ("Connect A") I want to disable the other button ("Connect B") and then preform a Network Connection

What is happening is that when I click the "Connect A" button the command to disable the "Connect B" button is delayed until the network connection has actually finished, which can be up to 3 seconds.

In my Select statements for the "Connect A" Button I have.

Code: Select all

DisableGadget(MainWindow_Button_ConnectB,1)
ConnectionID = OpenNetworkConnection("127.0.0.1", Port)
I have tried adding
UpdateWindow_(GadgetID(MainWindow_Button_ConnectB))
before the network connection but the disabling is still delayed.

So I added a DoEvents procedure before the network connection but the disabling is still delayed.

Is there a way to disable the "Connect B" button and then run the network connection once the button has actually been disabled.

Thanks
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Imediate Gadget Update

Post by RASHAD »

Try

Code: Select all

flags = #PB_Window_SystemMenu| #PB_Window_ScreenCentered
OpenWindow(0,0,0,400,300,"Test",Flags)
ButtonGadget(0,10,10,60,24,"Enabled")
ButtonGadget(1,10,44,60,24,"# 2")
Repeat
           
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1            
   
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
              DisableGadget(0,1)              
              SetGadgetText(0,"Disabled")
              Repeat
                x+1
                Delay(10)
              Until x >= 1000
              DisableGadget(0,0)              
              SetGadgetText(0,"Enabled") 
        
          EndSelect       

  EndSelect 

Until Quit = 1
End
Egypt my love
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Imediate Gadget Update

Post by nco2k »

put your netcode in a separate thread.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply