我试图每2秒读取一个excel文件,这个文件正在被其他RTD应用程序更新.
我能够通过Oledb连接读取此文件,但是当我尝试每2秒读取一次时会出现问题.在10次尝试中,它只能读取4-5次,而在其他尝试中,它会抛出异常.
连接字符串
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\nids\shes.xlsm;Extended Properties="Excel 12.0 Macro;HDR=Yes;IMEX=1"
Run Code Online (Sandbox Code Playgroud)
码
//opening connection to excel file
using (OleDbConnection connection = new OleDbConnection(constr))//constr = connection string
{
try
{
connection.Open();
isconopen = true;
}
catch
{
dispatcherTimer2.Start();
connection.Close();
isconopen = false;
}
// If connection is ok , then query sheet
if (isconopen == true)
{
strcon = "SELECT * FROM [" + dsheet + "]";
using (OleDbDataAdapter adapter = new OleDbDataAdapter(strcon, connection))
{
try
{
adapter.Fill(result);
isread = true;
adapter.Dispose();
connection.Close();
} …Run Code Online (Sandbox Code Playgroud) 我明天早上必须提交我的WPF项目; 它在VS 2010中运行得很好,但是在使用C#的VS 2008(两种情况下都是.NET 3.5)中出错了.
我正在使用计时器,Dispatcher.Invoke但在VS 2008中它给出错误:
错误163
最佳重载方法匹配System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate)包含一些无效参数.
以下代码给出错误:
Dispatcher.Invoke(new Action(() =>
{
// ANY ACTIONS HERE
.. some task
}), null);
Run Code Online (Sandbox Code Playgroud)
代码必须在VS 2008中运行.