作为事件处理程序的方法

时间:2013-12-17 14:34:49

标签: events asynchronous methods handler instances

任何人都可以帮我解决问题吗? 我有2节课。

public partial class StationTabItem : UserControl

{
SessionServiceClass.Instance.getHistoricalStationData(Convert.ToUInt32(station.stationNumber), setHistoricalStationData);    
 public void setHistoricalStationData(object sender, readStationDataHistoryCompletedEventArgs e)
    {

        if (!e.Cancelled && (e.Error == null))
        {
            historicalStationData = new List<StationData>();
            historicalStationData = e.Result.ToList();
            fillHistoricalData(historicalStationData);

            InitializeComponent();
            ComboBox_Left.SelectedIndex = leftIndex;
            ComboBox_Right.SelectedIndex = rightIndex;
            TextBlock_StationName.Text = stationName;
            TextBox_DetailsInfo.Text = evidUdajeStanice;
            fillStationData(station);
            updateDataGrids(localDynamicData_weatherData.variables, localDynamicData_alignedSurfaceData.variables, localDynamicData_oppositeSurfaceData.variables);

        }
    }

和第二课

public class SessionServiceClass
{
public void getHistoricalStationData(uint stationID, EventHandler<readStationDataHistoryCompletedEventArgs> setHistoricalStationData)
    {
        rwisClient.readStationDataHistoryAsync(stationID, System.DateTime.Today.AddHours(System.DateTime.Now.Hour).AddMinutes(System.DateTime.Now.Minute), -86400);

        rwisClient.readStationDataHistoryCompleted -= setHistoricalStationData;
        rwisClient.readStationDataHistoryCompleted += setHistoricalStationData;

    }
}

问题是,如果我创建了更多的StationTabItem实例,那么在每个实例中都会调用每个方法setHistricalStationData,但最后的结果是e.result。这意味着我的变量historicalStationData是覆盖它的最后一个值。 提前感谢任何想法。

0 个答案:

没有答案