Posted on 2003-03-31
I am writing an application that needs to read and write to files. The user chooses the file(s) to read from, and the app then reads the files byte by byte, and writes it into another file byte by byte.
This takes quite a long time, so I am trying to use the create thread API to Run this on a different thread.
The user may choose for example 10 files to copy. All of the info for these 10 files, eg, the file paths and names, how many files the user chose etc are stored in public variables. The thread is then called using create thread. Inside the thread, I define local versions of these variable, and copy the info from the public variable into the private variable. I then use the private variables in the thread.
This then frees the public variables for the user to select more files and create another thread if they want to.
The problem is that it crashes alot. I have declared the createthread(....) in the main form, and I have put the routine in a module. The thread is called in the main form using the click event of a button -> ID = createthread(,,addressof RoutineName, , , ID) - Please note, this is not how the thread looks in my project, I am at a different PC now and don't have the exact code with me. What I did want to find out though is that in some examples, they use the exact same variable, eg ID. In some examples I have seen they use a different variable, eg Thread = createthread(,,addressof RoutineName, , , ID). Which would be more correct, or doesn't it matter?
The project also craches alot. Sometimes it works, sometimes it give a fatal exception and sometimes it just closes the project and VB's design environment.
Is there any way to overcome this? If you need more details on the code I've used please let em know, Thanks,