Bug !! Bug !! How can we do?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phoebe

    #1

    Bug !! Bug !! How can we do?

    hi all, first,thank you for coming in!

    I have some problem on a Windows application in .Net Framework,just as
    below,also you can get the whole project in the attachment(in c#).

    private void button1_Click(o bject sender, System.EventArg s e)
    {

    WindowsApplicat ion1.localhost. Service1 ser=new
    WindowsApplicat ion1.localhost. Service1();
    textBox1.Text=s er.Add(int.Pars e(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 it would be expected that only one
    messagebox should be showed even though I click very quickly.To my
    knowledge,a windows form uses a single threaded apartment model(STA): when
    one button click event is be processing,the form shouldn't accept another.

    Absolutely,I can prevent it from a way:get the button1 disabled before
    calling a webservice and enabled it later.But ,as you can see,the project is
    a simple one just to test,while the reality is more complex.So,the above
    solution is not a very convincing way.I want to get a better one.

    Now,please unzip the attachment ,open the project in VS .Net 2003,and run it
    ..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.

    Most importantly:
    1. why would this happen in STA?
    2. How can the button1 continue accepting the click event when the form is
    loaded for the first time?
    3. How to control?

    I need your help!!! if you are also wondered about it,get help from people
    around you please. Thank you very much!


Working...