×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Please somebody finds out my mistakes. Thank you so much.

It seems never finish. BTW, the web service is ok in web app calling using the method waithandle. The following code is in windows application.
*********************************************
private void button2_Click(object sender, System.EventArgs e)
{
WindowsApplication1.SycAsyc.SycAsyc webAsyc=new WindowsApplication1.SycAsyc.SycAsyc();

AsyncCallback cb= new AsyncCallback(ServiceCallback);
IAsyncResult ar=webAsyc.BeginGetFile("asyc", cb, webAsyc);
while (ar.IsCompleted == false)
{ textBox1.Text="wait";
}

}

public void ServiceCallback(IAsyncResult ar)
{WindowsApplication1.SycAsyc.SycAsyc webAsyc = (WindowsApplication1.SycAsyc.SycAsyc) ar.AsyncState;
textBox1.Text = webAsyc.EndGetFile(ar);
}
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Please somebody finds out my mistakes. Thank you so much.
    It seems never finish. BTW, the web service is ok in web app calling using the method waithandle. The following code is in windows application.
    *********************************************
    private void button2_Click(object sender, System.EventArgs e)
    {
    WindowsApplication1.SycAsyc.SycAsyc webAsyc=new WindowsApplication1.SycAsyc.SycAsyc();

    AsyncCallback cb= new AsyncCallback(ServiceCallback);
    IAsyncResult ar=webAsyc.BeginGetFile("asyc", cb, webAsyc);
    while (ar.IsCompleted == false)
    { textBox1.Text="wait";
    }

    }

    public void ServiceCallback(IAsyncResult ar)
    {WindowsApplication1.SycAsyc.SycAsyc webAsyc = (WindowsApplication1.SycAsyc.SycAsyc) ar.AsyncState;
    textBox1.Text = webAsyc.EndGetFile(ar);
    }
    • Your problem is coming here tooooo of-ten.
      :rolia
      Where can I go?
      go to rolia
      never exit
      exit
      • :D:D
        no problem.
    • wrong way
      If I am not misunderstanding you, I think you are doing it in the wrong way. .Net provides standard asynchrous call to method of web service. I can submit your a zip file containing web service and client, but unfortunatelly, I do not know your email address.
      • 你就在这说说好了,我在MSDN和其它论坛search了半天, 发现用callback的例子大同小异,所以不知道怎么回事, 不用callback的asynchronous调用完全成功。谢谢!顺便顶给xmlhttprequest(DataSet lover...)看。
        • up!
          • 就是我说的原因啊:textBox1.Text = webAsyc.EndGetFile(ar); 不能在 callback 里面直接这么操作,要 merge 回 ui thread
            • 程序还没走到这一步
            • try this:
              this.BeginInvoke(new MethodInvoker(this.test)); // use this line in callback, 'this' is win form...

              private void test()
              {
              this.label1.Text = "abc";
              }
              • Thanks.
            • I tried in a console application, same problem. But, let me try. Thank you.
              what is the straight way to merge 回 ui thread ?
        • WindowsApplication1.SycAsyc.SycAsyc webAsyc=new WindowsApplication1.SycAsyc.SycAsyc();
          问题可能出在这一句,
          WindowsApplication1.SycAsyc.SycAsyc webAsyc=new WindowsApplication1.SycAsyc.SycAsyc();

          你debug 一下, 看webAsync的内容,是否created an instance.
          • that's the web service. nio problem here. It works.
    • add a Thread.Sleep(100) in your while loop and have a try.
      • good. I'm waiting for you. Thanks. :-)
      • The problem is thread.
        Thread.Sleep(100) doesn't work.
        If my asynchronous call doesn't use callback, I tried several ways, it works. if I use callback, the code I posted here, the Form no response anymore although the process is still running.
    • Tip: threads fired from WinForm should run on the control's thread....
      • Thanks so much. I succeeded just now. So exhausted.