小编Nid*_*rma的帖子

当其他进程使用OleDB c#时,读取Excel文件

我试图每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)

c# excel

7
推荐指数
1
解决办法
1万
查看次数

Dispatcher.Invoke在vs2010中工作但在vs2008中出错

我明天早上必须提交我的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中运行.

c# wpf compiler-errors timer dispatcher

0
推荐指数
1
解决办法
310
查看次数

标签 统计

c# ×2

compiler-errors ×1

dispatcher ×1

excel ×1

timer ×1

wpf ×1