simo el batali
simo el batali

Reputation: 11

prevent users to click the same button at the same time in .net windows forms application?

Is there a way to prevent users to click the same button at the same time in VB.net windows forms applications.

The application beeing installed locally at each user machine, We are facing some issues when 2 or more users click on the same button to call the same function or webservice.

Many Thanks

Mo

Upvotes: 1

Views: 290

Answers (3)

Minus
Minus

Reputation: 729

I would suggest implementing a design pattern like observer (see http://en.wikipedia.org/wiki/Observer_pattern for references) in the server side. You can also use a singleton to do it. Theses are only existing ideas to deal with those issues.

In the Observer one, it will holds a collection of Objects that is allowed to call methods. When one is executing, you can notify all the other to disable the button that call it and notifying back when process is done.

If you need more info, ask I will try to make it clearer.

Upvotes: 0

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239814

You need to cope with this, and adequately deal with it, in the webservice (or any other shared, central component).

Have the web service detect that another call has already started and return a distinctive error code or other message (or wait, and then perform the second request when the first has completed).

When you're dealing with multiple systems, or multiple resources outside of your program's immediate control, you need to recognize that no amount of pre-checking can prevent race conditions from occurring:

You could perform a check (determine that no-one else is doing action X) and then attempt to perform action X - in the small fraction of time between checking and performing, someone else may have started doing action X.

Upvotes: 3

Frank Thomas
Frank Thomas

Reputation: 2514

you can use the state of a Remoted Object to enable or disable the button, but I strongly suggest introducing asynchronicity so that you can block operations until other users have finished with their exclusive use of resources.

Upvotes: 0

Related Questions