NET岛

导航

访问和调用外部组件

访问.NET和COM组件
创建引用 Add Reference
使用 using 关键字

实例化ActiveX控件
添加引用
添加到Toolbox
拖放控件或代码方式

访问Web Service
添加web 引用 Add Web Reference
实例化 webService1 myService = new WebService1();
调用 myService.myMethod();
异步调用

public class AsyncDemo
{
  WebService1 myService;
  
public void CallMethodAsynchronously()
  
{
    myService 
= new WebService1();
    System.AsyncCallback myCallBack 
= new System.AsyncCallback(CallBack);
    myService.BeginMyMethod(myCallBack,
new object());
  }

  
public void CallBack(IAsyncResult e)
  
{
    
string myString;
    myString 
= myService.EndMyMethod(e);
  }

}

采用回调方式
public void AsyncDemo()
{
    WebService1 myService = new WebService1();
    IAsyncResult Async;
    //为回调方法创建委托
    System.AsyncCallback myCallBack = new System.AsyncCallback(SomeMethod);
    Async = myService.BeginMyMethod(myCallBack,new object());
    string myString;
    //程序暂停,直到调用返回
    myString = myService.EndMyMethod(Async);
}

访问Windows API
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int Beep(int dwFreq, int dwDuration);

posted on 2005-08-25 23:52  左佩玉  阅读(382)  评论(0编辑  收藏  举报