Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Ok so I've been busy on this problem, I'm receiving lets say multiple packets from the serial port, each with unique identifiers. What I want to do is have each ID open up in a diff window concurrently processing data along with all user interactions available, like button clicks and stuff.

I'm being quite picky here, if there is no solution I could do the boring thing and sort the different ID's and then open up multiple threads to do the work in the background, and then after the work is done display it.

So far I've read about MDI's, but not sure how that helps me. Opening up a new form for every new identifier perhaps? Not sure if I read wrong, but in a forum they said that the base form, from where the Second form is created waits until the Second form is done. Is this correct.

Any suggestions will be greately appreciated.

Thanks
Posted

 
Share this answer
 
Your UI should all be in one thread (weird things happen if that's not the case). It's trivial to create multiple forms, though you might want to reconsider that for usability reasons (for example making a tabbed interface or using MDI).

There is only one serial port, right? I don't understand why you want a thread for each ID. Instead, have one thread which is listening and dispatches messages to the appropriate message handler, which can then do whatever with it and update its UI.
 
Share this answer
 
Comments
codenameyash 20-Apr-11 10:09am    
one thread good idea I like
codenameyash 20-Apr-11 10:12am    
Oh one other thing there can be many connections incoming, upper limit has not been defined yet, anyway besides the point, you mention message handler and its UI, how does one create that, would that be another form with UI or something else?
BobJanova 20-Apr-11 11:26am    
The UI for a message handler in your proposal would be a form. I would suggest making it a TabPage or similar instead. But it is a control which is created at the same time as the message handler, on the main UI thread, and which is bound (either with real data binding or code) to the message handler.

The message handler is simply the class which is actually in charge of doing things with the messages, which is vague because we don't know what your program is actually doing. It can spawn threads to do heavy processing, or better run tasks through a ThreadPool (or Task stuff in .Net 4.0), and when the UI needs updating it should make that happen (by use of Invoke if necessary).
For having multiple dialogs active at the same time, you would need to create and open them modelessly. And once you do that each of them should use a background thread to do further processing.

You could consider using the Task Parallel library too but it may be kinda tricky in your specific scenario. Still doable I'd think. But I'd personally just go with the simple thread solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900