473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Excel Instance won;t die if coping cell content to struct

Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.

Dec 18 '06 #1
16 2664
Alexia,

You are leaving references open everywhere. Most notably, the object
returned by the Cells property, as well as each Range object returned when
you access the Item property on the Cells object.

You need to keep careful count of these and release all the references
on these in order to make sure the instance dies.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.

Dec 18 '06 #2

Nicholas Paldino [.NET/C# MVP] wrote:
Alexia,

You are leaving references open everywhere. Most notably, the object
returned by the Cells property, as well as each Range object returned when
you access the Item property on the Cells object.

You need to keep careful count of these and release all the references
on these in order to make sure the instance dies.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.
HI Nicholas and thanks for the reply,

I have no idea where i leave references open. as you see i close all
references. also, in this format the excel instance is dead. but when i
remove the commetns from lines 1.1,1.2 and 1.3 the excel reference
won't be killed.

Dec 18 '06 #3

Nicholas Paldino [.NET/C# MVP] wrote:
Alexia,

You are leaving references open everywhere. Most notably, the object
returned by the Cells property, as well as each Range object returned when
you access the Item property on the Cells object.

You need to keep careful count of these and release all the references
on these in order to make sure the instance dies.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.
Nicholas I don't see where she forgot to release any object. as for the
class, it is being destroied after she calls GC.

Dec 18 '06 #4
<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.


I don't get it, what exactly do you mean with "in this case the excel .... if i remove lines
1.1, .....
Do you mean that it works if you comment the lines (like above) but when you uncomment the
lines it fails ?
Are you running this on the UI thread or what?
The DoEvents() call makes me shiver......
Willy.
Dec 18 '06 #5

Willy Denoyette [MVP] wrote:
<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.

I don't get it, what exactly do you mean with "in this case the excel .... if i remove lines
1.1, .....
Do you mean that it works if you comment the lines (like above) but when you uncomment the
lines it fails ?
Are you running this on the UI thread or what?
The DoEvents() call makes me shiver......
Willy.
Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.

I am not running this on UI thread but in a public function inside a
form.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.

Dec 18 '06 #6
<al********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.

I am not running this on UI thread but in a public function inside a
form.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.
There is nothing wrong with DoEvents if used properly. If used incorrectly
it is dangerous because any code can become re-entrant. You should make sure
you handle the cases of users interacting with your GUI while a process is
running. It's probably better to use a second thread than doevents but that
introduces a new set of complexities and doesn't solve the issues with
DoEvents anyway (actually it would make all the issues worse:-)

With regards to the code you posted, can you post something a little more
compact. If you're paying me I'm happy to wade through excessive amounts of
code but in this case I'm presuming you want an answer for free. :-)

Michael
Dec 19 '06 #7

Michael C wrote:
<al********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.

I am not running this on UI thread but in a public function inside a
form.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.

There is nothing wrong with DoEvents if used properly. If used incorrectly
it is dangerous because any code can become re-entrant. You should make sure
you handle the cases of users interacting with your GUI while a process is
running. It's probably better to use a second thread than doevents but that
introduces a new set of complexities and doesn't solve the issues with
DoEvents anyway (actually it would make all the issues worse:-)

With regards to the code you posted, can you post something a little more
compact. If you're paying me I'm happy to wade through excessive amounts of
code but in this case I'm presuming you want an answer for free. :-)

Michael
No one sees the problem ?

Dec 19 '06 #8
<al********@gmail.comwrote in message
news:11*********************@a3g2000cwd.googlegrou ps.com...
No one sees the problem ?
I didn't even read the code posted as it was too long. Are you saying there
is a problem with the use of DoEvents in this particular code or in general?
>

Dec 19 '06 #9

Michael C wrote:
<al********@gmail.comwrote in message
news:11*********************@a3g2000cwd.googlegrou ps.com...
No one sees the problem ?

I didn't even read the code posted as it was too long. Are you saying there
is a problem with the use of DoEvents in this particular code or in general?
The problem is not in the DoEvent(). the problem is that if i read 5
columns from excel, then the instance won't die. if i comment 3 lines
that read the clumns(no matter which lines), then the instance is
killed.

I see no reason for this to happen, unless there's bug in MS COM Excel.

Dec 19 '06 #10
<al********@gmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
The problem is not in the DoEvent(). the problem is that if i read 5
columns from excel, then the instance won't die. if i comment 3 lines
that read the clumns(no matter which lines), then the instance is
killed.

I see no reason for this to happen, unless there's bug in MS COM Excel.
As I said, the code is too long for my short attention span. Post a smaller
example. If you want an answer for free you need to put in a little effort
yourself. :-)

Michael
Dec 19 '06 #11

Michael C wrote:
<al********@gmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
The problem is not in the DoEvent(). the problem is that if i read 5
columns from excel, then the instance won't die. if i comment 3 lines
that read the clumns(no matter which lines), then the instance is
killed.

I see no reason for this to happen, unless there's bug in MS COM Excel.

As I said, the code is too long for my short attention span. Post a smaller
example. If you want an answer for free you need to put in a little effort
yourself. :-)

Michael
Hi Michael. Here is a small shorter code..

Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
app = new Excel.ApplicationClass();
oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
frmMain.sDBTest frmmainsDBTestobj = new frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test = ((Excel.Range)oSheet.Cells[rowIndex,
2]).Value2.ToString();
//frmmainsDBTestobj.Teststatus = ((Excel.Range)oSheet.Cells[rowIndex,
3]).Value2.ToString();
//frmmainsDBTestobj.TestComment = ((Excel.Range)oSheet.Cells[rowIndex,
4]).Value2.ToString();
//frmmainsDBTestobj.TST = ((Excel.Range)oSheet.Cells[rowIndex,
5]).Value2.ToString();
//frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());

rowIndex++;
}

app.Workbooks.Close();
app.Application.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Dec 19 '06 #12
al********@gmail.com wrote:
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.
<snip>
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.
My Excel Interop knowledge is a little rusty at this moment, but since
you are not getting a solution I will give this a try.

From what I can see on your code, you are not releasing the Range
objects you are creaing.

When you write a line:
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 != null)

you are creating a lot of temporary Excel.Range objects, and never
releasing them.

Anywhere you use a range, you need to ReleaseComObject it.
For example the line:
frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex,3]).Value2.ToString();

should be more like:
Excel.Range Range = (Excel.Range)oSheet;
frmmainsDBTestobj.Teststatus =
Range.Cells[rowIndex,3]).Value2.ToString();
ReleasecomObject(Range);

If you get the code right and ReleaseComObject *every* object you
create, you should not need to call GC.Collect at all. (and neither
GC.WaitForPendingFinalizers()). In fact this GC.Collect call is what
makes your kind of random behavior, since it is not deterministic and
might release or not the pending objects.

I don't remember right now if you also need to call ReleasecomObjects
on the Cell object, but you might try this too. (I do not have a
development enviroment here to test it). Also, if you are reading more
than 3 values, it is a good idea to read entire ranges into arrays and
not cell by cell, since that can be very slow.

As I said before, there have been a lot of years since I last dealed
with this, and I am very happy I do not have to do it anymore :) But I
think this might help.

About myself, because exactly this kind of issues with ole (and many
more that you will find along the way), is that we created a component
to read and write Excel files without Excel. If you want to take a
look, ours is at http://www.tmssoftware.com/go/?flexcelnet, but there
are many more if you google. And they exist for a reason ;) I would
reccomend that you take a look, they might save you a lot of headaches.

Hope this helped.
Kind regards,
Adrian.

--

Dec 19 '06 #13
<al********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
>
Willy Denoyette [MVP] wrote:
><al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googleg roups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.

I don't get it, what exactly do you mean with "in this case the excel .... if i remove
lines
1.1, .....
Do you mean that it works if you comment the lines (like above) but when you uncomment
the
lines it fails ?
Are you running this on the UI thread or what?
The DoEvents() call makes me shiver......
Willy.

Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.
OK.
I am not running this on UI thread but in a public function inside a
form.
Not on the UI thread?, ARE YOU SURE about this?? Are you creating another thread from the UI
thread to run this code in?
If that's true, you are (trying) to update the UI from another thread which is "sin no. 1"
in Windows., you should never update the UI from another thread than the UI thread itself!
Tale a look at Control.Invoke or Control.BeginInvoke if you need to update the UI from
another thread.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.
A lot, and it should be avoided if ever possible. But at this moment it's even not relevant,
answer above question first .
Note also, as others said, you should post a complete sample that illustrates the issue,
from the snip you posted it's impossible to know what's wrong with this code
Willy.
Dec 19 '06 #14

Willy Denoyette [MVP] wrote:
<al********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...

Willy Denoyette [MVP] wrote:
<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.


I don't get it, what exactly do you mean with "in this case the excel .... if i remove
lines
1.1, .....
Do you mean that it works if you comment the lines (like above) but when you uncomment
the
lines it fails ?
Are you running this on the UI thread or what?
The DoEvents() call makes me shiver......
Willy.
Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.
OK.
I am not running this on UI thread but in a public function inside a
form.

Not on the UI thread?, ARE YOU SURE about this?? Are you creating another thread from the UI
thread to run this code in?
If that's true, you are (trying) to update the UI from another thread which is "sin no. 1"
in Windows., you should never update the UI from another thread than the UI thread itself!
Tale a look at Control.Invoke or Control.BeginInvoke if you need to update the UI from
another thread.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.
A lot, and it should be avoided if ever possible. But at this moment it's even not relevant,
answer above question first .
Note also, as others said, you should post a complete sample that illustrates the issue,
from the snip you posted it's impossible to know what's wrong with this code
Willy.
Hi Williy,

Here is the complete sample:

public class frmmainsDBTest
{
public int TestNumber;
public string Test;
public string Teststatus;
public string TestComment;
public string TST;
public bool iscomment;
};

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int rowIndex = 2;
string TestSetFile = @"D:\per\Eran\er.xls";
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
frmmainsDBTest frmmainsDBTestobj = new
frmmainsDBTest();
frmmainsDBTestobj.TestNumber =
int.Parse(((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
rowIndex++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
this.Visible = false;
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

//System.Runtime.InteropServices.Marshal.ReleaseComO bject((Excel.Range)oSheet.Cells);
//app.Application.Quit();

//System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
//app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
this.Visible = false;
}
}
}

Hope you are OK with it.

Dec 19 '06 #15
<al********@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
>
Willy Denoyette [MVP] wrote:
><al********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegr oups.com...
>
Willy Denoyette [MVP] wrote:
<al********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googleg roups.com...
Hi all,

In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.

here is a snipcode

public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBv iewList)
{
int rowIndex = 2;
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (TestSetFile.ToString() == "")
return null;

Application.DoEvents();

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
return null;
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
return null;
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;

while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

progressBar1.Maximum = rowIndex-2;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
progressBar1.Value = rowIndex-2;
frmMain.sDBTest frmmainsDBTestobj = new
frmMain.sDBTest();
frmmainsDBTestobj.TestNumber =
Int32.Parse(((Excel.Range)oSheet.Cells[rowIndex,
1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
// 1.1 frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
// 1.2 frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
//frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
// 1.3 frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
DBviewList.Add(frmmainsDBTestobj);
rowIndex++;
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message.ToString());
//app.Workbooks.Close();
//app.Quit();
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oWB);
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
return DBviewList;

}
In this case the excel instance is dying. if i remove lines 1.1,1.2
and1.3, then excel instance won't die.

sDBTest is a public class where all members are string besides
iscomment(bool).

Thanks for the help.


I don't get it, what exactly do you mean with "in this case the excel .... if i remove
lines
1.1, .....
Do you mean that it works if you comment the lines (like above) but when you uncomment
the
lines it fails ?
Are you running this on the UI thread or what?
The DoEvents() call makes me shiver......
Willy.

Hi Willy,

you are correct. it works if I comment the lines 3 (like above) but
when you uncomment the
lines it doesn't kill the excell instance.
OK.
I am not running this on UI thread but in a public function inside a
form.

Not on the UI thread?, ARE YOU SURE about this?? Are you creating another thread from the
UI
thread to run this code in?
If that's true, you are (trying) to update the UI from another thread which is "sin no.
1"
in Windows., you should never update the UI from another thread than the UI thread
itself!
Tale a look at Control.Invoke or Control.BeginInvoke if you need to update the UI from
another thread.
What's wrong with the DoEvents()? if i don't use the DoEvents() then
Windows doesn't refresh my form.
A lot, and it should be avoided if ever possible. But at this moment it's even not
relevant,
answer above question first .
Note also, as others said, you should post a complete sample that illustrates the issue,
from the snip you posted it's impossible to know what's wrong with this code
Willy.

Hi Williy,

Here is the complete sample:

public class frmmainsDBTest
{
public int TestNumber;
public string Test;
public string Teststatus;
public string TestComment;
public string TST;
public bool iscomment;
};

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int rowIndex = 2;
string TestSetFile = @"D:\per\Eran\er.xls";
Excel.ApplicationClass app;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

if (!File.Exists(TestSetFile))
{
MessageBox.Show("File " + TestSetFile + " Doesn't
exist...", "File not found!");
}

app = new Excel.ApplicationClass();
if (app == null)
{
MessageBox.Show("Excel could not be started.",
"Error");
}

oWB = app.Workbooks.Open(TestSetFile, 0, true, 5, "", "",
true,
Excel.XlPlatform.xlWindows, "\t", false, false, 0,
true, 1, 0);

oSheet = (Excel.Worksheet)oWB.ActiveSheet;
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2 !=
null)
rowIndex++;

rowIndex = 2;

try
{
while (((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2
!= null)
{
frmmainsDBTest frmmainsDBTestobj = new
frmmainsDBTest();
frmmainsDBTestobj.TestNumber =
int.Parse(((Excel.Range)oSheet.Cells[rowIndex, 1]).Value2.ToString());
frmmainsDBTestobj.Test =
((Excel.Range)oSheet.Cells[rowIndex, 2]).Value2.ToString();
frmmainsDBTestobj.Teststatus =
((Excel.Range)oSheet.Cells[rowIndex, 3]).Value2.ToString();
frmmainsDBTestobj.TestComment =
((Excel.Range)oSheet.Cells[rowIndex, 4]).Value2.ToString();
frmmainsDBTestobj.TST =
((Excel.Range)oSheet.Cells[rowIndex, 5]).Value2.ToString();
frmmainsDBTestobj.iscomment =
bool.Parse(((Excel.Range)oSheet.Cells[rowIndex, 6]).Value2.ToString());
rowIndex++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
this.Visible = false;
}

app.Workbooks.Close();
app.Application.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(app);

//System.Runtime.InteropServices.Marshal.ReleaseComO bject((Excel.Range)oSheet.Cells);
//app.Application.Quit();

//System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet);
//app.Workbooks.Close();
app = null;
oWB = null;
oSheet = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
this.Visible = false;
}
}
}

Hope you are OK with it.

No, I'm not, this is not a complete sample, Form1 is a partial class!

Willy.

Dec 19 '06 #16
<al********@gmail.comwrote in message
news:11*********************@a3g2000cwd.googlegrou ps.com...
Hi Michael. Here is a small shorter code..
That's better but it is of no use because I can't copy/paste it into a new
project and run it. What is frmMain, TestSetFile etc etc? I'm quite happy to
sift through this code and get it working but you will have to be paying me.
If you want an answer for free you have to post something that works staight
off.

Michael
Dec 19 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: farsta_online | last post by:
Hi, With ASP I store the result from form (textboxes and checkboxes) in a Access 2000 database. Now I want to use a Excel worksheet for presenting the data. What I want is partly to online...
2
by: Duncan Allen | last post by:
I've been using excel within VB.NET applications and I can't get it to close down and remove itself from memory. I'm using Visual Studio 2003 ver 7.1.3088, Framework 1.1, MS Office 2003 with MS VS...
2
by: Wendy Spray | last post by:
Hi I have an xml document that has been created from an excel spreadsheet. In the s/s there are some empty cells however these are not captured in the xml file. All that is added is for the cell...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
3
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
6
by: Kevin Humphreys | last post by:
Hi There, I am trying to export a recordset to an excel file using the Content Type below in the header. Response.ContentType = "application/vnd.ms-excel" Which works fine however the...
6
by: McKirahan | last post by:
I an using ASP to read a database table and generate an HTML table which is save via FSO with a file extension of .xls which opens up in MS-Excel. I am inserting several lines of text into a cell...
0
by: prakashsakthivel | last post by:
Hi Members One excel sheet has some external link through DDE. I want to move cell contents with data link while coping one excel to another excel sheet. I got only value not that link...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.