Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am having a network class and a dialog class.I have to send the data recieved in network class to dialog class but not direcly i.e it should not be tightly coupled with my dialog. Help me out..............
Posted
Comments
Sergey Alexandrovich Kryukov 13-May-11 4:05am    
The question makes some sense, my 4.
--SA

As suggested, your network class should run in a working thread, while the GUI runs in the main one, see the following Newcomer's article: "WorkerThreads"[^] (you may find a lot of useful assays in his webpage).

You may use, for instance, properly synchronized shared resources to hold incoming and outcoming data and messages (via, for instance, PostMessage) to make the network class notifying for data arrival.
 
Share this answer
 
v3
Comments
Albert Holguin 13-May-11 10:59am    
I don't know if synchronize is the correct term here... considering PostMessage is an asynchronous message... but proper methodology nonetheless, my 5...
This is really bad idea. Network data is coming and coming but dialog stays modal until the user closes it. There is apparent controversy between network stream and modal behavior. You need to run all your network application-level protocol in a separate thread (on server side typically in two threads, one accepting new connections, another one performing exchange with clients' network streams) — isn't this logical?

Your concern about tight coupling is absolutely correct.

So, your network events can notify UI, and the UI should show some data, status, etc. As I say, modal behavior hardly fits the networking design. Better show data in something like list box or list view. You can implement walking by the lost items and displaying some detail of data in some other control.

—SA
 
Share this answer
 
Comments
Olivier Levrey 13-May-11 4:18am    
Good advices. My 5.
OP is maybe using a non-modal dialog though (he didn't say). Anyway the general ideas about threading and data updating are good.
Sergey Alexandrovich Kryukov 13-May-11 4:31am    
Thank you, Olivier.

I know you C++ people often discuss non-modal dialog, but to my taste is sounds like oxymoron. Don't you feel the same way? As to any modal behaviour, I think their use should me strongly minimized, mostly reduced to well-known cases like "open file", "save file", etc.

Anyway, non-modal window would work a little better on the notification from the network thread, but only a bit; it's also not very adequate...
--SA
Olivier Levrey 13-May-11 4:46am    
I personnaly don't like non-modal dialogs much and use them in very rare cases. Users find them annoying, they don't know where to put them. However I do use modal dialogs quite often. Not only for loading/saving files: our users like wizards. They are mostly biologists and are often affraid about computers, so they appreciate to be guided. The ultimate rule could be: do not show them more than one button at a time otherwise you would stress them!
Sergey Alexandrovich Kryukov 13-May-11 4:57am    
The last principle is very wise, but the wizard is maybe not the best solution; people just used the them.
Good to know your opinion on dialogs, thank you.
--SA
CPallini 13-May-11 5:15am    
My 5.

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