开发者

threading problem (reading and writing to one excel file)

开发者 https://www.devze.com 2023-02-12 19:43 出处:网络
I have application, which do something. Generaly the main their task is to analise and drawing charts after getting data from excel file. This application can do at the same time max. 10 analise and e

I have application, which do something. Generaly the main their task is to analise and drawing charts after getting data from excel file. This application can do at the same time max. 10 analise and each of them are execute in a separate thread in a separate tabPage control. Everything is great to the moment when is appearing 3 problems.

  1. I can't reading data from one excel file do a few analises. If I'm using one file to one analise and I want to use this same file to another it's not possible beacuse there is some massage that this file is acctually using by another process. To read data from excel file i'm using oleDBConnection schema. How to solve this problem.

  2. I have this same problem to write data to one file. How to force my application to write same message from different threads to one file.

  3. If I want to close my application (when one of analise is working) there is show me some message with communication: "Interruption lasted thread (or something like that)". I don't know why. I support this

Please help me to solve this problems beacuse开发者_如何学Go I'm trying to solve it sice monday and there is no effect :(


Possible Example

string  FullExcelFilePath = "C:\ExcelFile.xls";


Excel.Application xlApp = new Excel.Application()

Excel.WorkBook xlWorkBook1 = xlApp.WorkBooks.Add(FullExcelFilePath);
Excel.WorkBook xlWorkBook2 = xlApp.WorkBooks.Add(FullExcelFilePath);

//then in your first ThreadCall
foreach(Excel.WorkSheet in xlWorkBook1.Sheets)
{
//get what you want
}


//then in your 2nd ThreadCal
foreach(Excel.WorkSheet in xlWorkBook2.Sheets)
{
//get what you want
}

OTHER Option you could do is:

You Could make a copy of the Xls for the other thread, and then

use a copy of the xls file in the Other Thread.

File.Copy(strFileName, strDestination);

then Afterwards Delete it

File.Delete(strFileNameSecondVersion)
0

精彩评论

暂无评论...
验证码 换一张
取 消