Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a server and a client that connect using TCP sockets. I pass data along the network stream when I click a button and receive data in return. My question is how can I stop the user spamming the button. When its clicked multiple times too quickly I get an error, and I think it's because its receiving too much data too fast. I want to stop the user spamming the button, but they do need to use it multiple times. Is there a way to detect if all send and receive operations are finished before I allow the user to do anything. Thanks.
Posted

you can take a flag bool type when send or receive operation occur the flag will be false. like

bool flag = true;

void SendOperation()
{
flag = false;
//your operation
flag = true;
}

void ReceiveOperation()
{
flag = false;
//your operation
flag = true;
}

when user click the button 1st check the flag status, if the flag status is true then your perform your operation, otherwise give a message to the user, sorry, please wait.
 
Share this answer
 
Comments
E.F. Nijboer 20-Oct-10 12:29pm    
Vote of 5 because this is exactly what I meant as well :-D
shakil0304003 23-Oct-10 4:33am    
Thanks :)
You can simply disable the button until the operation is done.

You can add a boolean to the form that you set to true as long as the operation is busy and when the button is clicked you only do the operation if this value is false.

A better method is to to add a property to the class that is doing the operation. This is better because this will ensure the operation to only start once, even if the method to start the operation is called from another place in the code. This way you prevent errors in the future when you could for example start the operation using a button but also from a menuitem.

Good luck!
 
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