清除会话对象中的列表

时间:2016-08-26 08:50:40

标签: vb.net

我对Vb很新。

我收到以下错误' Option Strict On禁止后期绑定'当我尝试清除我的seesionObject中的列表时,如图所示。

Private Sub ClearSessionList()
    Dim context As Object = System.Web.HttpContext.Current.Session("MySessionobject")
    context.MyListProperty = New List(Of String)
End Sub

当我尝试跟随强制转换时,错误仍然存​​在

DirectCast(context.MyListProperty, List(Of String))
CType(context.MyListProperty, List(Of String))

我认为我的演员阵容在某种程度上是错误的,有人可以为我指出错误并展示如何清除列表?

1 个答案:

答案 0 :(得分:0)

始终使用option strict,然后您无法访问MyListProperty,直到您从context ObjectMySessionObject投放Dim context As Object = System.Web.HttpContext.Current.Session("MySessionobject") Dim myObj As MySessionObject = DirectCast(context, MySessionObject) myObj.MyListProperty.Clear() 类型。否则VB.NET会尝试为你投射它,有时会产生奇怪的结果。

所以假设它的类型是 protected void click(JTable table) { JScrollPane pane=new JScrollPane(); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if(!combo_chau.getSelectedItem().toString().equals("station")) pane.setViewportView(tab_mat(table.getValueAt(table.getSelectedRow(), 2).toString(),table.getValueAt(table.getSelectedRow(), 3).toString())); if(combo_chau.getSelectedItem().toString().equals("station")) {pane.setViewportView(tab_sta(table.getValueAt(table.getSelectedRow(), 5).toString(),table.getValueAt(table.getSelectedRow(), 0).toString())); if(comboBox_1.getSelectedItem().equals("sans detail")) { pane.setViewportView(tab_sta_sansdetail(combo_cam.getSelectedItem().toString())); if(combo_cam.getSelectedItem().toString().equals("tout")) pane.setViewportView(tab_sta(table.getValueAt(table.getSelectedRow(), 5).toString(),table.getValueAt(table.getSelectedRow(), 0).toString())); } } if(table.getModel().getColumnName(((JTable) e.getSource()).getSelectedColumn()).equals("autre") ) { int result = JOptionPane.showConfirmDialog( frame, pane, "Use a Panel", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); } } }); }

public void timerControl()
{

    DispatcherTimer dtClockTime = new DispatcherTimer();

    dtClockTime.Interval = new TimeSpan(0, 0, 1); //in Hour, Minutes, Second.
    dtClockTime.Tick += dtClockTime_Tick;
    dtClockTime.IsEnabled = true;
    dtClockTime.Start();

}

private void dtClockTime_Tick(object sender, EventArgs e)
{
    getCPUInfo();
}

public void getCPUInfo()
{

    PerformanceCounter cpuCounter;
    cpuCounter = new PerformanceCounter();
    cpuCounter.CategoryName = "Processor";
    cpuCounter.CounterName = "% Processor Time";
    cpuCounter.InstanceName = "_Total";
    // Get Current Cpu Usage
    string currentCpuUsage =
    cpuCounter.NextValue() + "%";
    //Print it to the current label
    CPUUsage.Content = currentCpuUsage;
}