Reply to thread

Im having trouble with WCF Async service methods. I think this is a lack of understanding on my part, but I cant find anything that applies to my situation.


In short I would like to call a method and then perform work after getting the value.


To simplify my situation imagine this:


Form with two buttons and two listboxes.


Click button 1, and it calls the WCF and populates list 1;


Click button 2, and it calls the WCF and populates list 2;



In a typical situation, I would do this:


[code]

button1_handler

{

    listBox1.ItemsSource = dal.GetList("button1");

}

button2_handler

{

    listBox1.ItemsSource = dal.GetList("button2");

}

[/code]


the issue is this, in the Asnyc world I cant do that sicne the Async methods do not have return types but use callbacks.


[code]

dal.GetListComplete += (object sender, GetListEventArgs e) =>

{

    // here I must pick list one or two -- with no easy way

    // to know which button was clicked,

    listBox1.ItemsSource = e.Result;

};

//populate list of all Client OUs

dal.GetList("button1");

[/code]


I have the same issue even if I do not use an anonymous method for the event handler.


If I use the (sender) object, it seems very wasteful to make a large switch statement in the completed event handler to determin what list I should populate.


Any thoughts or ideas are really appreciated!


Back
Top