Going Loopy
Posted: Tue Feb 25, 2020 4:19 pm
Hi all, just needing some pointers on the correct way or best way to do this :-
The grabfile() procedure is essentially readfile(0,file$) : while not eof(0) : Text$ = ReadString(0) : addgadgetitem(item, -1, text$) : Wend
Using this approach causes the Main Window to become unresponsive and this is understandable, but I can't figure out the best way to do this without making the Window unresponsive.
I wanted to create a progressbar and I tried using a Thread - I got it working but the compiled executable was at least 4 times slower than it was when I ran the application in the IDE. (I believe this has something to do with Threadsafe and the slow down of strings)
Anyway, just really looking for some input on the best way to do this e.g. are threads the way to go or is there a better way to handle the loading of a file into a gadget?
The grabfile() procedure is essentially readfile(0,file$) : while not eof(0) : Text$ = ReadString(0) : addgadgetitem(item, -1, text$) : Wend
Using this approach causes the Main Window to become unresponsive and this is understandable, but I can't figure out the best way to do this without making the Window unresponsive.
I wanted to create a progressbar and I tried using a Thread - I got it working but the compiled executable was at least 4 times slower than it was when I ran the application in the IDE. (I believe this has something to do with Threadsafe and the slow down of strings)
Anyway, just really looking for some input on the best way to do this e.g. are threads the way to go or is there a better way to handle the loading of a file into a gadget?
Code: Select all
If CreateMenu(0, WindowID(Main))
MenuTitle("File")
MenuItem(#Menu_File_Open, "&Open..." + #TAB$ + "Ctrl+O")
AddKeyboardShortcut(Main, #PB_Shortcut_Control|#PB_Shortcut_O, #Menu_File_Open)
MenuBar()
MenuItem(#Menu_File_Exit, "&Exit" + #TAB$ + "Ctrl+Q")
AddKeyboardShortcut(Main, #PB_Shortcut_Control|#PB_Shortcut_Q, #Menu_File_Exit)
EndIf
BindEvent(#PB_Event_Menu, @OnMenuEvent(),Main)
BindEvent(#PB_Event_Gadget, @OnEventGadget())
BindEvent(#PB_Event_SizeWindow, @OnEventSize(),Main)
BindEvent(#PB_Event_CloseWindow, @Quit())
;BindEvent(#PB_Event_Timer,@OnTimer())
Repeat: WaitWindowEvent() : ForEver
Code: Select all
Procedure OnMenuEvent()
Select EventMenu()
Case #Menu_File_Open
;Progress()
filepicker()
grabfile(file$)
Case #Menu_File_Exit
Quit()
EndSelect
EndProcedure