Tarma
Tarma

Reputation: 143

Q: How to serialized parallel connection with FIFO Queue?

I use a C# class with a serial function to connect my application to a CNC machine - the project is a MDI.

The serial function is called by different child forms (there are 5 of them).

In another class, created to handle connections, I will create a FIFO queue for managing the requests from the child forms.

The child forms will communicate with the connection class via socket. Is this a good idea?
If not, is there another method to do this?

I'm thinking at this mode:

private struct s_fifoObj
    {
        public int priority;    //Priority of serial command
        public DateTime data;   // Date of command
        public string from;     // That form send the comand
        public string cmd;      // the command (request)
        public int status;      // status of command
    }

    private Queue<s_fifoObj> q_fifoObj;

Upvotes: 1

Views: 142

Answers (1)

noggin182
noggin182

Reputation: 637

Is there a reason you are using sockets to communication between the child forms and the connection handler? You could create an instance of your connection handler in your parent MDI window and then pass this into the child windows constructor. Or you could make your connection handler a singleton

Do you need a queue? If your application is single threaded then you don't need a queue. If you are using multiple threads/tasks or using async functions, then a FIFO will work but be sure to make sure of ConcurrentQueue in System.Collections.Concurrent, or something else that is thread safe.

Upvotes: 1

Related Questions