BUG?: Office Tools in Workflow Activity

I've been creating custom activities for my workflow that

make use of VSOT. Compiling, running or working with these activities

open multiple copies of both winword and excel in the background without

closing them, slowly eating up resources until they are closed manually.

Activities make use of the Microsoft Excel & Word 11.0 Object Component Libraries

with each making a new instance of ApplicationClass and or Document.

Let me know if you want me to supply some code samples, glitch found using beta 2.2

[548 byte] By [EdwardSmeathers] at [2007-12-22]
# 1
Please post the code for you custom activities? If you do the same thing without using workflow do you have the same problem?
TomLake at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
I've just tried the same code in a console application with no problems so i do assume that it is either my code in the workflow activity, or a bug in windows workflow code as follows

CreateHymnSheet.cs (workflow activity)
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using WorkflowActivitys.Resources;
using System.Data;

namespace WorkflowActivitys
{
[ToolboxBitmap(typeof(CreateHymnSheet), "Resources.WordIcon.png")]
[Designer(typeof(CreateHymnSheetDesigner))]

public partial class CreateHymnSheet : Activity
{
public static DependencyProperty Funeral_IDProperty = DependencyProperty.Register("Funeral_ID", typeof(int), typeof(CreateHymnSheet));
DataSet Arrangements = new DataSet();
Commands SQL = new Commands();
WordOfficeTasks OT = new WordOfficeTasks();

public CreateHymnSheet()
{
InitializeComponent();
}

[ValidationOption(ValidationOption.Required)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[DescriptionAttribute("Funeral_ID is used to access the correct data when producing the Document")]
public int Funeral_ID
{
get
{
return ((int)(base.GetValue(CreateHymnSheet.Funeral_IDProperty)));
}
set
{
base.SetValue(CreateHymnSheet.Funeral_IDProperty, value);
}
}

protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
{
try
{
Console.WriteLine("CreateHymnSheet Activity");
Arrangements = SQL.LookupFuneral_Arrangements(Funeral_ID);
OT.ProduceHmynSheet(Arrangements);
return ActivityExecutionStatus.Closed;
}
catch
{
throw;
}
}
}
}

CreateHymnSheet.cs (workflow activity)
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace WorkflowActivitys.Resources
{
class WordOfficeTasks
{
private ApplicationClass WordApp = new ApplicationClass(); // new instance of word
private Document WordDoc = new Document(); // new instance of document

public void ProduceHmynSheet(DataSet Arrangements)
{
object missing = System.Reflection.Missing.Value; // 'void' value
object filename = @"D:\hymnsheet.dot"; // word template to use

WordApp.Visible = false; // tell word not to show itself

WordDoc = WordApp.Documents.Add( // load the template into a document workspace
ref filename, // and reference it through our myWordDoc
ref missing,
ref missing,
ref missing);

// string of tags that exsist in word template
string[] tags = new string[] {"<location_line1>","<location_line2>","<first_name>","<surname>",
"<year_birth>","<year_death>","<date_of_service>"};

// sting of values to exchange tags for
string[] values = new String[] {Arrangements.Tables["Interment_Location"].Rows[0]["Location_Name"].ToString(),
Arrangements.Tables["Interment_Location"].Rows[0]["Address"].ToString(),
Arrangements.Tables["Funeral_Arrangements"].Rows[0]["Deceased_Fornames"].ToString().ToUpper(),
Arrangements.Tables["Funeral_Arrangements"].Rows[0]["Deceased_Surname"].ToString().ToUpper(),
((DateTime)Arrangements.Tables["Funeral_Arrangements"].Rows[0]["Deceased_Date_of_Birth"]).ToString("yyyy"),
((DateTime)Arrangements.Tables["Funeral_Arrangements"].Rows[0]["Deceased_Date_Time_of_Death"]).ToString("yyyy"),
((DateTime)Arrangements.Tables["Funeral_Arrangements"].Rows[0]["Interment_Date_Time"]).ToString("dddd d MMMM yyyy")};

object replaceAll = Word.WdReplace.wdReplaceAll;

for (int i = 0; i < tags.Length; i++)
{
// find tag from tag[] string array
WordApp.Selection.Find.Text = tagsIdea;
// replace with value from values[] string array
WordApp.Selection.Find.Replacement.Text = valuesIdea;
// call find and replace
WordApp.Selection.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
}

//Button[] Hymns = new Button[Arrangements.Tables["Hymns"].Rows.Count];

//for (int i = 0; i < Arrangements.Tables["Hymns"].Rows.Count; i++)
//{
// HymnsIdea = new Button();
// HymnsIdea.Text = Arrangements.Tables["Hymns"].RowsIdea["Hymn_ID"].ToString();
// //WordDoc
// //ActP.Controls.Add(HymnsIdea);

//}
WordApp.Visible = true;
}

This code does rely on a few more classes and then an SQL database but it should give you a good enough idea of what i'm doing

EdwardSmeathers at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3
Are you still having this problem? Have you tried it on the released version of the product?
TomLake-MSFT at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified