小编Eu *_*upu的帖子

OpenFileDialog默认路径

using (var openFileDialog1 = new OpenFileDialog())
        {
            openFileDialog1.Reset();
            if (!string.IsNullOrEmpty(ExcelFilePath))
            {
                string fileName = Path.GetFileName(ExcelFilePath);
                string fileExt = Path.GetExtension(ExcelFilePath);
                //Avoid "you can't open this location using this program file" dialog 
                //if there is a file name in the path strip it )
                if (!string.IsNullOrEmpty(fileName))
                    initialDirectory = Path.GetDirectoryName(ExcelFilePath);  
      //if not let it be   
                else
                    initialDirectory = ExcelFilePath;

            openFileDialog1.InitialDirectory = initialDirectory;
            }
            else
                openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Excel files (*.xls or *.xlsx)|*.xls;*.xlsx";
            //openFileDialog1.Filter = "xls files (*.xls)|*.xls|xlsx files(*.xlsx)|.xlsx";
            openFileDialog1.FilterIndex = 2; …
Run Code Online (Sandbox Code Playgroud)

c#

20
推荐指数
3
解决办法
9万
查看次数

检测到ContextSwitchDeadlock

我在调试模式下运行类似于以下代码的东西:

for (int i = 0; i < 5000; i++)
{
   for (int j = 0; j < 10; j++)
   {
     DoSomething();
   }
}
Run Code Online (Sandbox Code Playgroud)

我不时会从VS 2010中检测到"已检测到ContextSwitchDeadlock".似乎性能会随着可用RAM的减少而降低.我有8GB并且能够在大约8分钟内运行程序(循环完成后有很多DB命中,所以8分钟不是循环时间),在4GB机器上时间加倍!从我的红色开始,MDA被解雇是因为我的循环运行时间超过60秒.从本质上讲,它是一个警告,代码完全阻止了应用程序.

我该怎么做才能避免这些情况并提高速度?

谢谢!

c# debugging visual-studio visual-studio-debugging

3
推荐指数
1
解决办法
5523
查看次数

查找文件是否正在使用 - 特别是xls文件

检查出下面的链接并尝试使用那里提出的方法没有结果.我的问题涉及使用OLEDB提供程序从Excel文件导入,由于某些我无法理解的原因,当文件在Excel中打开时,导入显示一些列(例如日期)作为文本,它不会发生在文件未被使用.我的问题可以通过检查xls文件是否打开/正在使用来暂时解决,因此我可以发布一条消息,要求用户关闭该文件.

谢谢,Mihail

https://www.google.com/search?rlz=1C1RNHN_enUS465US465&ix=hea&sourceid=chrome&ie=UTF-8&q=stackoverflow.

c# oledb

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