Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frnds...



i m developing chat application its desktop application...its database driven application... i m using timer for geting new message,new request ..


but problem is that it give slow response on user interface..like i m doing operation like add contact,delete contact...



which concept i use?

process running on background not affect on user interface...

give me suggestion ..


can i use asynchronous threading for that ....?

and asynchronous threading has four method ...so

pls give me suggestion which method i use for asynchronous threading.. ?
Posted
Comments
OriginalGriff 7-Apr-11 2:24am    
Without seeing the relevant code fragments, It is pretty much impossible to work out where the slow down is, and whether threading would help significantly.
Edit your question, and provide relevant code fragments: don't just dump the whole code, nobody is going to wade through it looking!

There is a lot to it, hard to answer all together.
Also, I don't know your setting. What do you want, a Web Service? Web application? P2P chat?

Just a few ideas. First principal: don't create a thread per client! All clients should be served by one thread. The number of threads should be fixed or configurable, created once per server's lifetime: something like this: main thread, one thread for database, one or two threads for listening for new users and authentication, one common thread for user interactions. The threads can communicate through the blocking message queue (I have a generic queue implementation, a faster implementation is available in the Framework v. 4.0).

You can find some idea in my past Answers. Sorry, they are written in response to different Question ans some items can be irrelevant, but you also did not provide exact information on what you want. Please see:
Multple clients from same port Number[^]
Thread wrapper, very useful to avoid the problem of passing parameters:
How to pass ref parameter to the thread[^]
Collection of other related references:
How to get a keydown event to operate on a different thread in vb.net[^]
My article on blocking message queue, full code with usage samples:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

It all needs certain study. Further details highly depend on you requirements and decisions. Hope it can help you.

Good luck,
—SA
 
Share this answer
 
Comments
Abhinav S 7-Apr-11 3:28am    
Great answer. 5.
Sergey Alexandrovich Kryukov 7-Apr-11 4:05am    
Thank you very much, Abhinav.
--SA
As SA already pointed out, there is more in it. But the problem is, that all database call is made in the UI thread with then blocks you program. If you are using .NET 4, take at look at System.Threading.Tasks[^]

There it is possible to start a new Task that fetch new rows from the database and then display then in the UI.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Apr-11 4:10am    
I would not recommend using tasks for this particular purpose (they use threads anyway, they are like sub-allocator in global heap (this is just my metaphor)), as using fixed amount of explicit threads is better. Again, for this particular purposes. For more dynamic and non-deterministic settings tasks can be of great value, but extra dynamic threading for server is evil.
As to database, I already mentioned there must be a separate thread.

--SA

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