RegListSubKey Problem

Just starting out? Need help? Post your questions and find answers here.
oridan
Enthusiast
Enthusiast
Posts: 128
Joined: Tue Oct 12, 2004 12:14 am
Location: Italy
Contact:

RegListSubKey Problem

Post by oridan »

Hello,
I have a problem with RegListSubKey.
Here my code:

Code: Select all

Enumeration
  #Window
  #Text
  #List
  #Start
  #Stop
  #Pause
EndEnumeration

Procedure GetList()
Index=0 
Key.s = ""
KeyValue.s = ""
ClearGadgetItemList(#List)
SetGadgetText(#Text,"Scanning: 0" + " keys")
While RegListSubKey("HKEY_CLASSES_ROOT\CLSID",Index,".")<>""
  Key.s = RegListSubKey("HKEY_CLASSES_ROOT\CLSID",Index,".")
  ;Debug Key
  If RegKeyExists("HKEY_CLASSES_ROOT\CLSID\"+Key.s,".")
    KeyValue.s = "HKEY_CLASSES_ROOT\CLSID\"+Key.s
    ;Debug KeyValue
    AddGadgetItem(#List, -1, KeyValue)   
  EndIf   
  Index+1
  SetGadgetText(#Text, "Scanning: " + Str(index) + " keys")
Wend
If thread
  KillThread(thread)
  thread = 0
EndIf
  DisableGadget(#Stop, 1)
  DisableGadget(#Start, 0)
  DisableGadget(#Pause, 1)
EndProcedure

Procedure OpenWindow_Window_0()
  If OpenWindow(#Window, 120, 212, 800, 300, "RegListSubKey", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
    If CreateGadgetList(WindowID(#Window))
      ListIconGadget(#List, 10, 10, 780, 230, "Items", 400, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      TextGadget(#Text, 10, 242, 200, 15, "Scanning: 0" + " keys")
      ButtonGadget(#Start, 10, 260, 120, 26, "Start")
      ButtonGadget(#Stop, 150, 260, 120, 26, "Stop")
      ButtonGadget(#Pause, 290, 260, 120, 26, "Pause")
      DisableGadget(#Stop, 1)
      DisableGadget(#Pause, 1)
    EndIf
  EndIf
EndProcedure

OpenWindow_Window_0()

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Start
        thread = CreateThread(@GetList(), 0)
        DisableGadget(#Stop, 0)
        DisableGadget(#Start, 1)
        DisableGadget(#Pause, 0)
        Debug thread
      ElseIf EventGadget = #Pause
        If paused = 0
          PauseThread(thread) 
          Paused = 1
          SetGadgetText(#Pause, "Resume")
        Else
          Paused = 0 
          ResumeThread(thread)
          SetGadgetText(#Pause, "Pause")
        EndIf
        ElseIf EventGadget = #Stop
        If thread
          KillThread(thread)
          thread = 0
        EndIf
        DisableGadget(#Stop, 1)
        DisableGadget(#Start, 0)     
        DisableGadget(#Pause, 1)
      EndIf

    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window
        CloseWindow(#Window)
        Break
      EndIf
  EndSelect
ForEver
1) If you click on Start button start scanning of the keys
2) If you click on Pause button the scanning it is in pause
3) If you click on Resume button the scanning it restarts
4) If you click on Stop button the scanning it is stopped
5) If you repeat the scanning it doesn't restart...! :(

Can you help me?
Thanks in advance
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

oridan wrote:

Code: Select all

Procedure GetList()
...
  If thread
    KillThread(thread)
    thread = 0
  EndIf
...
Endproc 
This may or may not be the cause of your problem. It certainly doesn't help it.
I don't think you want to kill a thread from within the thread itself. :shock:
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Doesn't a thread "die" when you do a ProcedureReturn ?, if so you'll only have to free the thread handle from the main code (I think?).
Post Reply