views:

202

answers:

5

I have to implement client server based app where client is windows app. Now, my plan is to create a webservice as a server app and use it in our client app. But the problem is in notification. For this, I need to add a timer to the client app to check for the notification. It slows down the client app.

What is the best approach to do this?

I need to create setup for both app. So, the solution must be deploy-able.

Edit: I can't put timer in background or seperate thread because I have to update datagridview immediately.

A: 

By "create a webservice as a server app and use it in our client app" I assume you mean you are going to access the web service through a proxy, and not actually host the web service in your client app.

Are you running your timer on a background thread? I get the impression that you are using a timer to poll the web service and it's tying up your UI, causing the slowdown (of course, there are other factors to consider, but this is the one that seems most likely to me at the time).

casperOne
updated question.
Brij
A: 

what do you do to "check for the notification"? This might be a silly suggestion but starting a new thread to do this might mitigate the hit on the client app?

Linton Caldecott
A: 

If you are using WCF, then you may need to consider Duplex services

duplex service contract is a message exchange pattern in which both endpoints can send messages to the other independently. A duplex service, therefore, can send messages back to the client endpoint, providing event-like behavior. Duplex communication occurs when a client connects to a service and provides the service with a channel on which the service can send messages back to the client. Note that the event-like behavior of duplex services only works within a session.

so this avoids the timer problem..

Some links worth consider

Cheers

Ramesh Vel
+1  A: 

Use a BackgroundWorker or the Threadpool.QueueUserWorkItem for your calls to the webservice, then update your GUI. Your app slows down because you are calling the webservice from the main UI thread so your application cannot handle other events until the webservice call is done, that includes repaint, resize, clicks...

See this document : http://msdn.microsoft.com/en-us/library/ms951089.aspx

You want to update immediately by calling a remote resource? I'm afraid that isn't possible unless we dump one of the laws of thermodynamics and allow for time travel.

BUT you can cheat and prefetch your data and bind it behind the scenes every XXX seconds.

Remember to use BeginUpdate and EndUpdate when updating your grid so you don't get any flicker.

Florian Doyon
A: 

The suggestions to do the check on another thread are correct even if you need to update your UI with the results. Just make sure you use the InvokeRequired property and BeginInvoke method on your form. BeginInvoke will dispatch the call to the UI thread. See What's up with BeginInvoke? for a far more complete explanation with sample code. Also, as Florian Doyon said, don't forget to use BeginUpdate and EndUpdate on your DataGridView.

Cory McCarty