Results 1 to 12 of 12

Thread: Can multi-threading run safely under VB6 IDE?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,291

    Can multi-threading run safely under VB6 IDE?

    For example, you can operate the VB6 control in multithreading,LISTBOX to add data.
    Or three threads, with each thread's execution status displayed in three LABEL controls or three text boxes?
    VB6 IDE often breaks down after the program ends. I don't know what happened.

    like this:
    VB6-MultiThread-Download
    https://www.vbforums.com/showthread....hread-Download

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,291

    Re: Can multi-threading run safely under VB6 IDE?

    Maybe one day it will be possible to write code directly in VB6, and then use TWINBASIC parser and compiler when running and debugging?

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    4,893

    Re: Can multi-threading run safely under VB6 IDE?

    tB will support command line compilation before 1.0, it's likely we can get in auto import->compile too.

    For an example of what you're talking about, look at my VBEventTrace program. It collects ETW events in one thread, synchronizes it via a buffer with the main thread, then presents the data in a ListView.

    There's both a VB6 version using The trick's multithreading module, and an x64 compatible twinBASIC version using the CreateThread API directly. Though it's not a single codebase.

  4. #4
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,632

    Re: Can multi-threading run safely under VB6 IDE?

    multi-threading is not simple.

    we are used to sequential coding while multi-threading is about running simultaneously.
    the problem is when they talk with each other.
    in my own multi-thread approach it is important with:

    - App1: Create Server1
    - App1: Launch App2
    - App2: Create Server2
    - App2: Create Client2
    - App2: Tell App1, Im ready
    - App1: Create Client1

    as u see I need Client1/2 + Server1/2 (or integrated) to make it work.
    each step need to wait for the other or it will cause a crash.
    the same is the termination procedure. it need to be called in a sequential matter.
    the Clients/Servers need to be uninitialized correctly.
    and the same when sharing something, it need to be 100% correct or it can cause a crash.

    sure u can have many different approaches. but the idea is the same,
    things need to be in order and multi-threading is not about order but 2 different "existences"
    that need to work together.

    this is my only attempt of multi-thread. using executables.
    I wouldn't know what to do with CreateThread API.
    it seems very complicated and I wouldn't dare to try it.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    4,893

    Re: Can multi-threading run safely under VB6 IDE?

    The API is simple enough... you merely specify the address of a function and it calls it. Deceptively simple.

    The real problems come when you inevitable want to move data back and forth. For example in my event tracer, I had an array of UDTs that made up the event log. One thread would receive events and write to it, the other would read from it and display the events. Well, this would only run for 30s or so before crashing. That turned out to be because two threads can collide... the main thread tried to read at the exact moment it was being written, and boom. So to fix that, every operation on the shared array I enclosed in a critical section: You initialize it with InitializeCriticalSection, then both threads before touching the shared object call EnterCriticalSection, which blocks until the first thread to enter it is done and calls LeaveCriticalSection.

    And that's a fairly simple method. There's many, many others for this purpose... mutexes, semaphores, spin locks..

  6. #6

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,632

    Re: Can multi-threading run safely under VB6 IDE?

    fafalone ic. so API itself is easy and if u know a bit, u can use things such CriticalSection to avoid crashes.
    making such functionality and if done correctly u can now use multithread.

    one of the most important things is:
    - when do u need it

    when u code, it can be that u figure out that some code could be handled in another thread.
    this is not always obvious when u start a project. or maybe for some of u, but for me, I tackle things progressively.
    so, when I reach to that point I already got tons of code written. now I need to figure out how to "move it" into another thread. not that easy always.

    - how complex is the code. is it just an API or multiple calls/apis or even user input.

    this is also a problem. because its about the back and forth thing u mention. what method to use and when to know when its ready.

    in my "approach" I use mapped-memory and I use
    getmem1 to read "1" byte. if 0=nothing.
    this is called once a loop. (whatever that means, could be 1/60, once a second etc)
    when that byte is >0 I know something is there to be processed. in the same time I use Putmem1 and zero it AND I move the "position".
    so next getmem1 is not the same but "x" position ahead until we reach max mapped memory and it will start from 0 again.
    that means, the server can put many commands into the memory and do not need to wait until the client processed it.
    for this is also an issue with multi-tread, if TH1 sends 3 commands/data within 1 seconds and TH2 receive it but can not handle the load, as it needs 2 seconds to process it?

    that is the principle of it. and as u see very much VB6-style as I "think" 1-dimension.
    both "client/server" have its own mapped memory.
    this to avoid conflicts if APP1&APP2 would try to access the same in the same time. and that I know one is for "IN" and one is for "OUT".

    but this is my approach and require an app.
    using API such a CreateThread and calling another API will not use such method.

    right now Im comfortable using 2 applications.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,291

    Re: Can multi-threading run safely under VB6 IDE?

    That's been bothering me for years.Use the Critical region function. Well, lock it and unlock the function. The name is too long for me to remember. Today I finally remembered that I could get an alias for it. Hehe. I can use four characters instead.
    Is there another atom that adds or subtracts?
    Microsoft's API has a long and stinking name.
    Code:
    lock area1
    lock area2
    unlock area
    
    function lockA()
    lockapi area1
    end function
    Last edited by xiaoyao; Sep 21st, 2023 at 05:54 PM.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,291

    Re: Can multi-threading run safely under VB6 IDE?

    vb6 ide It is indeed possible to run multiple threads. You can also close the form and run it again.As long as the form does not involve VB 6, it will not crash basically.

    Sometimes normal code, um, runs multiple times and it crashes.
    People who understand assembly can debug why it crashes. This problem has been solved, that is, it does not disclose the method.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,291

    Re: Can multi-threading run safely under VB6 IDE?

    Quote Originally Posted by The trick View Post
    VB6 IDE doesn't support thread debugging.
    maybe
    You can solve this problem in a few months.

  11. #11
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,422

    Re: Can multi-threading run safely under VB6 IDE?

    There is a difference between running in the IDE and debugging in the IDE. The modified Multithread Download program runs in both the IDE and compiled, but you cannot halt the program anywhere in a thread without it crashing. I have found that for the most part, the Debug.Print statement seems to work just fine without the need for CriticalSection.

    My attempt at IOCP sort of works in the IDE, but fails miserably when compiled. Without being knowledgeable of exactly how IOCP works, and the intricacies of VB6 and the IDE, it is going to be very difficult to put that one together.

    By placing the bulk of the thread code in a class module, the class itself can be debugged separately and then added as is to the threaded program.

    J.A. Coutts
    Last edited by couttsj; Sep 23rd, 2023 at 02:41 PM.

  12. #12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width