Problems inserting values into project

H

Hans-Henrik Olesen

Hi!
I'm attempting to insert work from our time registration system into plan.

I have created an addin that does this by getting the data from a
webservice and inserting the values in to the active plan, but I get a
"An unexpected error occurred with the method" com exception after
inserting a few times.

I've heard of problems with the reference count (Project only capable of
handling 10 references to an object) and have unsuccessfully tried to
compensate for this by active garbagecolletion

I have also experimented with the type of the object I'm inserting - so
far, strings have been the best choice.

The following code generate an exception after 10 insertions (i == 10),
if I open a plan with one task in it and then run the code.
The start and end date of the task have no influence on the result.

Any help with this problem is appreciated.
Hans-Henrik Olesen

private void VersionButton_Click(CommandBarButton Ctrl, ref bool
CancelDefault)
{
for(int i = 0; i< 40; i++)
{
InsertValue("8", new DateTime(2004, 08, 25).AddDays(i));
//System.GC.Collect();
}
}

private void InsertValue(string value, DateTime date)
{
MSProject.Project CurrentProject = CurrentApplication.ActiveProject;
MSProject.Task tsk = CurrentProject.Tasks[1];
MSProject.TimeScaleValues TSVs = tsk.TimeScaleData(date, date,
MSProject.PjTaskTimescaledData.pjTaskTimescaledActualWork,
MSProject.PjTimescaleUnit.pjTimescaleDays, 1);
MSProject.TimeScaleValue TSV = TSVs[1];
try
{
TSV.Value = value;
}
catch(Exception exp)
{ MessageBox.Show(
exp.StackTrace.ToString());
}
}
 
L

Lars Hammarberg

Does the project calendar allow entering data on all days or do you have
non-working days within the date range (i.e. within 10 days from 25th Aug
2004) - which could possibly throw an exeption when trying to add data to
that particular day?

/Lars Hammarberg
www.camako.se
 
H

Hans-Henrik Olesen

Thanks!
That helped alot!

I stil have a problem the 11th time I try to insert a value but this can
be fixed by calling ActiveWindow.Refresh() on the application object and
then call System.GC.Collect() before I try to insert the 11th value.

I don't know why this is necesary and I would be a much happier person
if someone could tell me, but for now, it's working.

Thank's for the help!

/Hans-Henrik

Lars said:
Does the project calendar allow entering data on all days or do you have
non-working days within the date range (i.e. within 10 days from 25th Aug
2004) - which could possibly throw an exeption when trying to add data to
that particular day?

/Lars Hammarberg
www.camako.se


Hi!
I'm attempting to insert work from our time registration system into plan.

I have created an addin that does this by getting the data from a
webservice and inserting the values in to the active plan, but I get a
"An unexpected error occurred with the method" com exception after
inserting a few times.

I've heard of problems with the reference count (Project only capable of
handling 10 references to an object) and have unsuccessfully tried to
compensate for this by active garbagecolletion

I have also experimented with the type of the object I'm inserting - so
far, strings have been the best choice.

The following code generate an exception after 10 insertions (i == 10), if
I open a plan with one task in it and then run the code.
The start and end date of the task have no influence on the result.

Any help with this problem is appreciated.
Hans-Henrik Olesen

private void VersionButton_Click(CommandBarButton Ctrl, ref bool
CancelDefault)
{
for(int i = 0; i< 40; i++)
{
InsertValue("8", new DateTime(2004, 08, 25).AddDays(i));
//System.GC.Collect();
}
}

private void InsertValue(string value, DateTime date)
{
MSProject.Project CurrentProject = CurrentApplication.ActiveProject;
MSProject.Task tsk = CurrentProject.Tasks[1];
MSProject.TimeScaleValues TSVs = tsk.TimeScaleData(date, date,
MSProject.PjTaskTimescaledData.pjTaskTimescaledActualWork,
MSProject.PjTimescaleUnit.pjTimescaleDays, 1);
MSProject.TimeScaleValue TSV = TSVs[1];
try
{
TSV.Value = value;
}
catch(Exception exp)
{ MessageBox.Show(
exp.StackTrace.ToString());
}
}
 
L

Lars Hammarberg

When stepping through code using a debugger, the time-phased data sometime
displays erratic behaviour - sometimes displaying the correct value in the
"Watch" window and failing to deliver that same value to the variable I'm
trying to fill - sometimes just bugging out whereas the same code running
without me watching it will succeed... probably quantum mechanics
involved...

/Lars Hammarberg
www.camako.se

Hans-Henrik Olesen said:
Thanks!
That helped alot!

I stil have a problem the 11th time I try to insert a value but this can
be fixed by calling ActiveWindow.Refresh() on the application object and
then call System.GC.Collect() before I try to insert the 11th value.

I don't know why this is necesary and I would be a much happier person if
someone could tell me, but for now, it's working.

Thank's for the help!

/Hans-Henrik

Lars said:
Does the project calendar allow entering data on all days or do you have
non-working days within the date range (i.e. within 10 days from 25th Aug
2004) - which could possibly throw an exeption when trying to add data to
that particular day?

/Lars Hammarberg
www.camako.se


Hi!
I'm attempting to insert work from our time registration system into
plan.

I have created an addin that does this by getting the data from a
webservice and inserting the values in to the active plan, but I get a
"An unexpected error occurred with the method" com exception after
inserting a few times.

I've heard of problems with the reference count (Project only capable of
handling 10 references to an object) and have unsuccessfully tried to
compensate for this by active garbagecolletion

I have also experimented with the type of the object I'm inserting - so
far, strings have been the best choice.

The following code generate an exception after 10 insertions (i == 10),
if I open a plan with one task in it and then run the code.
The start and end date of the task have no influence on the result.

Any help with this problem is appreciated.
Hans-Henrik Olesen

private void VersionButton_Click(CommandBarButton Ctrl, ref bool
CancelDefault)
{
for(int i = 0; i< 40; i++)
{
InsertValue("8", new DateTime(2004, 08, 25).AddDays(i));
//System.GC.Collect();
}
}

private void InsertValue(string value, DateTime date)
{
MSProject.Project CurrentProject = CurrentApplication.ActiveProject;
MSProject.Task tsk = CurrentProject.Tasks[1];
MSProject.TimeScaleValues TSVs = tsk.TimeScaleData(date, date,
MSProject.PjTaskTimescaledData.pjTaskTimescaledActualWork,
MSProject.PjTimescaleUnit.pjTimescaleDays, 1);
MSProject.TimeScaleValue TSV = TSVs[1];
try
{
TSV.Value = value;
}
catch(Exception exp)
{ MessageBox.Show(
exp.StackTrace.ToString());
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top