bug !!bug !! on windows synchronization!!

P

phoebe

hi all, I have some problems on a Windows application in .Net Framework,just
as below:
private void button1_Click(object sender, System.EventArgs e)
{

WindowsApplication1.localhost.Service1 ser=new
WindowsApplication1.localhost.Service1();
textBox1.Text=ser.Add(int.Parse(textBox1.Text),1).ToString();
MessageBox.Show("ok");

}
you know, A webservice named ser is called in the above function,and ,when
the main form is loaded for the first time,if I click the button1 on the
form very quickly,the awful thing would happen:a messagebox is showed,when I
close it ,another messagebox is opened,I continue closing, and the same
thing happen:a messagebox is showed.The number of messageboxes is according
to the speed of my mouse clicking.

so, it seems the button1 still accept the click event while a webservice is
being called for the first time.But I expect only one messagebox would be
showed even though I click very quickly.How to control? hope your help!!!
Thank you!
 
R

Rob Tillie

phoebe said:
hi all, I have some problems on a Windows application in .Net
Framework,just as below:
private void button1_Click(object sender, System.EventArgs e)
{

WindowsApplication1.localhost.Service1 ser=new
WindowsApplication1.localhost.Service1();
textBox1.Text=ser.Add(int.Parse(textBox1.Text),1).ToString();
MessageBox.Show("ok");

}
"..."
so, it seems the button1 still accept the click event while a
webservice is being called for the first time.But I expect only one
messagebox would be showed even though I click very quickly.How to
control? hope your help!!! Thank you!

Nope, button1 doesn't accept a click while its calling the webservice.
Everytime you click, the webservice is called, it WAITS for the result and
then puts the result in a textbox. This will however be no noticeable delay
(when on localhost).

So I do not understand why the messagebox keeps showing up... can you maybe
explain a little bit more? you only click the button on the msgbox and then
a msgbox shows up again?

Greetz,
-- Rob.
 
P

phoebe

When the form is
loaded for the first time,you must click the button1 very quickly,then you
will see that status:msgboxes show up again and again! After you close all
of msgboxes,if you click the button1 again very quickly,only a msgbox will
show.
 
R

Rob Tillie

Indeed, when you click the button the first time, it executes the event handler, but you can still click the button again, thus executing the method a couple of times. I resolved it by Disabling the button when entering the method:

private void button1_Click(object sender, System.EventArgs e)

{

button1.Enabled = false;

WindowsApplication1.localhost.Service1 ser=new WindowsApplication1.localhost.Service1();

textBox1.Text=ser.Add(int.Parse(textBox1.Text),1).ToString();

MessageBox.Show("ok");

button1.Enabled = true;

}

Greetz,

-- Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top