C#异步事件过程不会触发

时间:2010-04-14 15:52:52

标签: c# asynchronous

我正在使用一个API,该API具有一些在完成时与事件过程异步调用的方法。我可以执行这些方法,但事件过程似乎没有触发。注意:我昨天发布了一个类似的问题,但直到很久以后才发布代码。我希望有人能发现我出错的地方

public partial class Window1 : Window
{
ClientAppServer newServer= new ClientAppServer();

public Window1()
{
    InitializeComponent();

    //the event thats supposed to fire
     newServer.ReceiveRequest += ReadServerReply;
}


private void ReadServerReply(RemoteRequest rr)
{
    //this point is never reached
    MessageBox.Show("reading server reply");
    if ((rr.TransferObject) is Gateways)
    {
        MessageBox.Show("you have gateways!");
    }
}


private void login()
{
//API docs says this is an asynchronous call        
newServer.RetrieveCollection(typeof(Gateways), true);

}


private void button1_Click(object sender, RoutedEventArgs e)
{
    this.login();
}

1 个答案:

答案 0 :(得分:1)

它是哪种API?这可能有助于我们解决这个问题。

从你发布的代码来看,它看起来并不像RetrieveCollection方法与接收请求有任何关系 - 它看起来不应该触发。

就建议而言,我假设您已尝试在事件处理程序上设置断点。如果您没有库的源代码,可以使用Reflector查看您的库正在做什么,并检查它是否应该触发该事件。

http://www.red-gate.com/products/reflector/