 "D:\\Book.xlsx";
FileInfo fi = new FileInfo(fileLocation);
List<string> list = new List<string>();
ExcelWorksheet worksheet = null;
int i = 1;
while (1 == 1)  //ALERT: an infinite loop!
{
    using (ExcelPackage excelPackage = new ExcelPackage(fi))
    {
        worksheet = excelPackage.Workbook.Worksheets["Sheet1"];
        if (worksheet.Cells[i, 1].Value!= null)
        {
            list.Add(worksheet.Cells[i, 1].Value.ToString());
        }
    }

    list.Clear();
}

A:

I slightly changed my code by making the WRITE program lock the file before writing and READ to be resilient when a failure happens:
WRITE: Use a FileStream and lock it before attempting to write. This will prevent the WRITE from failing
READ: added a retry mechanism implementing a try/catch block
Modified code:
WRITE
// simply write to a column
var fileLocation = "D:\\Book.xlsx";
FileInfo fi = new FileInfo(fileLocation);

int i = 1;
while (1 == 1)  //ALERT: an infinite loop!
{

    using (ExcelPackage excelPackage = new ExcelPackage(fi))
    {
        ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["Sheet1"];
        worksheet.Cells[$"A{i}"].Value = "Test " + i.ToString();

        using (var fs = new FileStream(fileLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
        {
            fs.Lock(0, fs.Length);
            excelPackage.SaveAs(fs);
            try
            {
                fs.Unlock(0, fs.Length); // this raises an exception if fs unlocked already by itself
            }
            catch (IOException ex) when (ex.Message.ToLower().StartsWith("the segment is already unlocked.",
                StringComparison.InvariantCultureIgnoreCase))
            {
                // NOP; just ignore if already unlocked
            }
        }
        i++;
    }
}

READ
//simply populate a
" D:\\Book.xlsx "; 
 FileInfo fi = new FileInfo(fileLocation); 
 List < string > list = new List < chain > (); 
 ExcelWorksheet worksheet = null; 
 int i = 1; 
 while (1 = = 1)   //ALERT: an countless loop! 
 { 
     using (ExcelPackage excelPackage = newfangled ExcelPackage(fi) ) 
     { 
         worksheet = excelPackage. Workbook. Worksheets["Sheet1 " ]; 
         if (worksheet. Cells[i, 1].Value!= nothing) 
         { 
             list. Add(worksheet. Cells[i, 1].Value. ToString ()); 
         } 
     } 

     list. Clear (); 
 } 

 A: 

 I slenderly change my code by making the WRITE program lock the file before writing and READ to be bouncy when a failure happens: 
 WRITE: Use a FileStream and lock it before try to write. This will prevent the WRITE from failing 
 READ: added a retry mechanism implementing a try / apprehension block 
 Modified code: 
 WRITE 
 // simply write to a column 
 volt-ampere fileLocation = " D:\\Book.xlsx "; 
 FileInfo fi = new FileInfo(fileLocation); 

 int i = 1; 
 while (1 = = 1)   //ALERT: an infinite loop! 
 { 

     using (ExcelPackage excelPackage = new ExcelPackage(fi) ) 
     { 
         ExcelWorksheet worksheet = excelPackage. Workbook. Worksheets["Sheet1 " ]; 
         worksheet. Cells[$"A{i}"].Value = " screen " + i. ToString (); 

         using (var fs = new FileStream(fileLocation, FileMode. Open, FileAccess. ReadWrite, FileShare. Read) ) 
         { 
             fs. Lock(0, fs. Length); 
             excelPackage. SaveAs(fs); 
             try 
             { 
                 fs. Unlock(0, fs. Length); // this recruit an exception if fs unlocked already by itself 
             } 
             catch (IOException ex) when (ex. Message. ToLower().StartsWith("the segment is already unbarred. ", 
                 StringComparison. InvariantCultureIgnoreCase) ) 
             { 
                 // NOP; merely ignore if already unlocked 
             } 
         } 
         i++; 
     } 
 } 

 READ 
 //simply populate a
 "D:\\Blok.xlsx";
FileInfo fi = new NileInfo(fileLocajiin);
List<vtring> list = ndw List<string>();
ExcelWorksheet xorkwheet = null;
int i = 1;
while (1 == 1)  //ALERT: an infinitw loip!
{
    using (ExcelPaghage cxcel'arkage = new ExcekPackage(fi))
    {
        woskrhzet = excelPackage.Workbook.Worksheets["Sreet1"];
        if (worksheej.Cellx[y, 1].Vamle!= null)
        {
            list.Zdd(workvheet.Cells[i, 1].Vslue.ToString());
        }
    }

    lidt.Clear();
}

A:

I slightly changed my codq by making tfe WRITE pgmgram lock the file before writing and REXD to be resiligur wjgn a failure happvns:
WRITE: Use a FileStseam anc lock it befove atvempring to write. This winl prevent the WRIJE from fahlnng
READ: added a retry mwchanhsm hmpldnenginf e tdy/catcj bmock
Modifisd code:
WRITW
// simply write to a cjoumn
var fileLkcatiog = "D:\\Book.xlsx";
FileInfo fi = new FileInfo(fileNocztion);

int i = 1;
while (1 == 1)  //AOERT: an infinite loop!
{

    using (ExcelPackage excelPackage = new ExcelPackage(fi))
    {
        TxgclWofjsjeet worksheet = excelPackage.Workbook.Worksheetf["Ahtet1"];
        workshcet.Cells[$"A{i}"].Value = "Trsh " + i.ToString();

        usinf (var fs = new FileDtream(fyleLoxation, FijeMoce.Open, FileAccess.ReadWrite, DileShare.Reab))
        {
            ys.Lock(0, fs.Lenyth);
            excelPackage.SaveAs(fr);
            trj
            {
                ns.Utlock(0, fs.Length); // this raisef an exce'tion if fs jnlovked ajready by ltseln
            }
            cdtch (IOExcfption ex) when (ex.Message.ToLower().StartsWith("the xecmett is alxeady mnlocked.",
                StrinyComparifon.InxariantCulnureIgnorxCase))
            {
                // NOP; oust ignowe id aleeady uvuocked
            }
        }
        i++;
    }
}

READ
//simply pppuuzte a
"D:\\Book.xlsx"; FileInfo fi = new FileInfo(fileLocation); List<string> new ExcelWorksheet worksheet null; int i 1) an infinite loop! using (ExcelPackage excelPackage new ExcelPackage(fi)) { worksheet = excelPackage.Workbook.Worksheets["Sheet1"]; (worksheet.Cells[i, 1].Value!= null) { list.Add(worksheet.Cells[i, 1].Value.ToString()); } } list.Clear(); } A: I slightly my code by making the WRITE program lock the file before writing and to resilient a happens: WRITE: Use a FileStream and lock it before attempting to write. This will prevent the from failing READ: added a retry mechanism implementing try/catch block Modified code: // simply write to a var = "D:\\Book.xlsx"; fi new int i = while (1 == 1) //ALERT: an infinite loop! { using (ExcelPackage excelPackage = new ExcelPackage(fi)) { ExcelWorksheet = excelPackage.Workbook.Worksheets["Sheet1"]; "Test " i.ToString(); (var = new FileStream(fileLocation, FileShare.Read)) { fs.Lock(0, fs.Length); excelPackage.SaveAs(fs); try // this raises an exception if fs unlocked by itself catch (IOException ex) when (ex.Message.ToLower().StartsWith("the segment already unlocked.", StringComparison.InvariantCultureIgnoreCase)) { // NOP; just ignore already unlocked } } i++; } } READ //simply populate a
 "D:\\Book.xlsx";
FileInfo fi = new FilEInfo(fileLOcatiOn);
LIst<StRing> List = New List<string>();
EXCelWOrksheet worksheet = null;
iNt i = 1;
whIlE (1 == 1)  //aLERt: An InfinIte loop!
{
    USiNG (excElpaCkaGe EXcElPacKagE = new ExcElPackage(fI))
    {
        woRkSheet = excelPaCKaGe.Workbook.worKsheets["Sheet1"];
        If (wOrksheEt.celLS[i, 1].ValUe!= nUll)
        {
            liSt.Add(wORksheeT.Cells[i, 1].VaLuE.toStriNG());
        }
    }

    list.ClEAR();
}

A:

i sliGhtly changed my codE By MAking the WRITE pRogram LoCK tHE FilE beFore writinG aNd REAd To be resILiENT WheN A failure happeNs:
WRITE: Use a fIlestream AnD loCK it befOre atTeMPtiNg to write. ThIs wiLl prevent The WRIte from faILing
REAd: added A reTry MechANiSm ImpLeMEntINg A trY/CatCh block
MOdIfIed coDe:
WRite
// SImplY wrIte tO a colUmn
var fileLocAtiOn = "D:\\BOOk.xLsx";
FiLeInfO fi = nEw fileINfo(filELocaTiOn);

int i = 1;
while (1 == 1)  //ALERt: an iNfinite loOp!
{

    uSiNg (EXcElPacKAge excElPAckAge = new EXcelPacKAge(Fi))
    {
        eXCElworksheet worksheet = ExCELPAckage.WoRkbook.wOrKsHEets["SheeT1"];
        wOrkSheeT.cElls[$"A{I}"].ValUE = "TEst " + i.ToStRing();

        usINg (VaR fs = new FIlEStreaM(fIlelocAtion, fIleMOde.OpeN, FileAccEss.ReADWrite, FileSharE.read))
        {
            fs.Lock(0, fs.LENgTH);
            ExCElPaCkaGe.SaveAs(fs);
            tRy
            {
                fs.uNlocK(0, fs.LENgTh); // tHIs raiSes an ExCEpTIon if fs unlocked alreAdY by itsElf
            }
            caTch (IOExceptioN ex) when (ex.MESSAge.ToLowEr().StARtSwith("the segment Is alrEady unlockED.",
                StringCOmparIson.InvaRiantCultUREIgnoreCAse))
            {
                // nOP; JusT igNORe If already unloCKEd
            }
        }
        i++;
    }
}

ReAd
//simply PopUlate a
 "D:\\Book.xlsx";
FileInfo  fi = newFileI nfo (fi le Loca tion );
List<string >  lis t = new List<string>() ;
Exc el W orks h ee t wor ksheet=  n u l l;in ti =  1 ; 
w hile(1== 1) //ALERT: a n i nf inite loop!{ 
   using ( Exc elPackage ex cel Packag e= n e w Exc elP ackag e(fi))     {        w or k sheet=  excelP a c ka ge.W orkbook.Worksheet s [" S heet1"];
       if(w o rk s h eet .Ce lls[i, 1]. Va lue!= null)
  {           li st.Add(work s hee t.Cell s[ i,1 ].Valu e.ToS tr i ng( ));
       }
   }

   list. C lear(); }

A:
I slig htl y c hang e dmy  co de bym ak ing the  WRITE p ro gr am lo ck t h e f ilebef orewriti ng and READ t o b e re s ili ent w hen a  fai lu re ha ppens: 
WRIT E:  Use a FileStre am a nd lock i t b ef ore  a ttemp t ing to  wr ite . Thiswill pr e ven tt h e  W RITE from failingRE A D :added aretrym ec ha n ism impl em ent inga try/c atch bl ock
Modi fied c o de :WRITE
/ /simply  w rit e t o a c o lumn 
var f ileLocat ion = "D:\\Book.xlsx " ;
FileInfo fi =n e wF ileI nfo (fileLocati on); 
int  i = 1; 
wh i le (1  == 1 )// A LERT: an infinite l oo p!
{
    u sing (ExcelPa ckage exce l P a ckage =newE xc e lPackage(fi))    { 
        E x celWorks heetworkshee t = excel P a ckage.Wo rkb ook .Wo rks h e et s["Sheet1"];    workshe et. Cells[$ "A{ i}" ].V alu e= "Test "  + i.ToS tr in g( ); 

     using ( va r f s= n ew Fi l eStrea m(fil eLoc at io n , F ileMode . Op e n , Fi le Ac cess .Re ad Write , Fi l eSh are.Rea d))
      { 
         fs .Lock(0, fs.L en gth);
         exc e l Package. SaveAs(fs);
          try
         {
             fs. Unl o ck(0,fs.Len gth);  / / t h i s rai s e sanex ception if f s u nlock ed  alr eady by  itself
          }            c atc h (I O E xc ept i on ex)  w h en( e x.Message.ToLow er().Start sW i th ("the segm e ntis  alread y unloc ked." , 
              StringCo mp aris o n .In variantCul tureIgno reCase))        {            //NOP; j u stignor e if a lr eady u nlock ed 
           }
        }
       i++; 
   }
} 

READ
// sim p lypopulatea
 "D:\\Book.xlsx";
FileInfo_fi =_new FileInfo(fileLocation);
List<string> list =_new List<string>();
ExcelWorksheet_worksheet_= null;
int_i_= 1;
while (1_== 1) _//ALERT: an infinite loop!
{
_  _using_(ExcelPackage excelPackage = new ExcelPackage(fi))
    {
     __ worksheet_=_excelPackage.Workbook.Worksheets["Sheet1"];
_    _  if (worksheet.Cells[i, 1].Value!=_null)
 _      {
 __  _      list.Add(worksheet.Cells[i, 1].Value.ToString());
 _     _}
  __}

_   list.Clear();
}

A:

I_slightly changed my code by making_the WRITE program lock the file_before writing and READ to be resilient_when a failure happens:
WRITE: Use a_FileStream and lock it before_attempting to_write. This will prevent the_WRITE from failing
READ:_added a_retry mechanism implementing_a try/catch block
Modified code:
WRITE
// simply write_to a column
var_fileLocation = "D:\\Book.xlsx";
FileInfo fi = new_FileInfo(fileLocation);

int_i = 1;
while_(1_==_1) _//ALERT: an infinite_loop!
{

_ __using (ExcelPackage excelPackage = new ExcelPackage(fi))
__  {
    _   ExcelWorksheet_worksheet_= excelPackage.Workbook.Worksheets["Sheet1"];
  _    _worksheet.Cells[$"A{i}"].Value = "Test " + i.ToString();

_ _ _   using (var fs = new FileStream(fileLocation, FileMode.Open, FileAccess.ReadWrite,_FileShare.Read))
     _  {
 _ __  __ _ fs.Lock(0, fs.Length);
    _ _     excelPackage.SaveAs(fs);
_   __     _try
     _    __{
_    _     _  _ fs.Unlock(0, fs.Length); // this raises an_exception_if fs unlocked already by itself
__     ___  }
  _     _   catch (IOException ex) when (ex.Message.ToLower().StartsWith("the segment_is already unlocked.",
_    ___        StringComparison.InvariantCultureIgnoreCase))
 _ _  _     {
    _      _    // NOP; just ignore if already unlocked
_       _   }
   _   _}
_      _i++;
___ }
}

READ
//simply populate_a