Threads and files...

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andy.

When using several threads, is it then possible to access files, from within the threads, which were opened before calling the threads?

Andy
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
Originally posted by Andy

When using several threads, is it then possible to access files, from within the threads, which were opened before calling the threads?

Andy
Its possible:

Code: Select all


Procedure ReadOpenedFile(FileNum.l)
UseFile(FileNum)
MessageRequester("string",ReadString(),0)
CloseFile(FileNum)
EndProcedure



If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  ButtonGadget(1,200,100,50,25,"Test")
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
    
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 1
            If OpenFile(0,"somedata.txt");create a file and store some string
              WriteString("1234567")
              CloseFile(0)
            EndIf
            
            If OpenFile(1,"somedata.txt");open the file and call the procedure in a thread
              ThreadID = CreateThread(@ReadOpenedFile(),1)
            EndIf
            
        EndSelect
    
    EndSelect
    
  Until EventID=#PB_EventCloseWindow
EndIf
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andy.

Ricardo,

Thank You very much:)

I just bought PB, and I find the help a little hard to understand, but this messageboard is SO HELPFUL!

Thanks mate, I'll check out Your code right away!

Andy
Post Reply