I'm updating legacy code, written in VB6, and I've come across the need for a mutex. I have two sockets, and I need to send and receive from various sources. So I plan on having one socket continuously listening for incoming connections, then the other is used to send or receive.
A timer checks twenty times a second if a connection has come in, and if so, uses the second socket to accept it, then begins listening again immediately. If a second connection comes in before the first has finished receiving data, it needs to wait (in C# I'd throw a lock on it and call it done.)
Also, if the program needs to send data, I'll use the second socket, and connect to the remote host. So if the second sockets already receiving data, it needs to block as well.
I'm not familiar with multithreading in VB6 - is this a problem, or is the timer's Tick
event always raised on the same thread as everything else?