Windows Workflow Foundation 3


Invoking workflow from windows form


Hi,
I have a simple windows form with a submit button. In the same solution I have a workflow project which I want to be called in the click event of this submit button. Below is the code under the click event.
// Create an instance of the workflow runtime
_workflowRuntime = WorkflowFactory.GetWorkflowRuntime();
_workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);
_workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(workflowRuntime_WorkflowCompleted);
// Create the argument.
Dictionary<string, object> parms = new Dictionary<string, object>();
parms.Add("CName", cmbColor.SelectedItem);
// Create instance.
_workflowInstance = _workflowRuntime.CreateWorkflow(typeof(ComputeZipCode.Workflow1), parms);
_workflowInstance.Start();
ComputeZipCode.Workflow1 is the workflow project that I want to be invoked. When I debug the solution the lines under the workflow project are executed but I dont see anything printed on the console (I have some console.writeline messages in the workflow).
Am not sure what is wrong.
Below is my WorkFlowFactory.cs file code
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime;
namespace WorkflowHost
{
public static class WorkflowFactory
{
// Singleton instance of the workflow runtime
private static WorkflowRuntime _workflowRuntime = null;
// Lock (sync) object
private static object _syncRoot = new object();
// Factory method
public static WorkflowRuntime GetWorkflowRuntime()
{
// Lock execution thread in case of multi-threaded
// (concurrent) access.
lock (_syncRoot)
{
// Check for startup condition
if (null == _workflowRuntime)
{
// Provide for shutdown
AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkflowRuntime);
// Not started, so create instance
_workflowRuntime = new WorkflowRuntime();
// Start the runtime
_workflowRuntime.StartRuntime();
} // if
// Return singleton instance
return _workflowRuntime;
} // lock
}
// Shutdown method
static void StopWorkflowRuntime(object sender, EventArgs e)
{
if (_workflowRuntime != null)
{
if (_workflowRuntime.IsStarted)
{
try
{
// Stop the runtime
_workflowRuntime.StopRuntime();
}
catch (ObjectDisposedException)
{
// Already disposed of, so ignore...
} // catch
} // if
} // if
}
}
}
Hi,
I noticed you host the workflow in a Windows Form application. According to the document, you should not use the Console class to display output in unattended applications, such as server applications. Similarly, calls to methods such as Write and WriteLine
have no effect in Windows applications.
http://msdn.microsoft.com/en-us/library/43zwz7ys
As an alternative, you can write the output to a file or call MessageBox.Show("Message test")Leo Tang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Related Links

Cant set breakpoint on Custom StateActivity
Correlation Token and Correlation Parameter
DelayActivities and useActiveTimer
Custom Persistence and CompletedScope table
WorkFlow - timer
EnqueueItem for transactional delivery of data
WorkFlowRuntime with events (ASp.Net)
Workflow on the fly
Windows Workflow and ASP.Net
State Machine "Undo" to previous state
Bind workflow property to a read-only activity property
Developing an application for a service support provider.
WorkflowRuntime.CreateWorkflow Performance
Access sequential workflow dependency property from custom activity
Access to workflow queues from external processes
Persiste in a custom activity

Categories

MSDN
Windows Desktop Develo...
Windows Phone Development
Internet Explorer Deve...
Machine Translation an...
Windows Embedded Compact
SQL Server (Pre-release)
Dynamics
Feedback and Discussions
Development
Office Live Development
Microsoft Atlas API: D...
Unified Communications
Archived Forums N-R
Skype for Business
Announcements for all ...
Visual C++
C++ Standards, Extensi...
Visual Studio Setup an...
Visual Studio Tools fo...
Test Tools in Visual S...
Visual Studio Unit Tes...
Application Insights (AI)
Developing Universal W...
Publishing Windows Sto...
Payouts and Reporting
AdSDK Integration & Ad...
Network Monitor
Windows Imaging Compon...
Windows Hardware Testi...
General Office Develop...
SharePoint 2013 - Gene...
Developing Apps for Sh...
SharePoint 2010 - Usin...
Azure Active Directory
Azure BizTalk Services
Azure Virtual Machines
Azure Backup
Azure Log Analytics
StorSimple
Azure Service Fabric
Azure SQL Data Warehouse
Azure IoT Hub
Azure Stack
Azure Database for Pos...
Azure Time Series Insi...
Common Language Runtim...
Team Foundation Server...
Team Foundation Server...
Architecture General
BizTalk Server Adapter...
Commerce Server 2007
JScript Native
Scripting
Microsoft Device Emulator
Windows Mobile Develop...
SQL Server Replication
SQL Server Security
SQL Server Manageability
SQL Server Distributed...
SQL Server In-Memory T...
Standard 7: Tools
Standard 7: Misc
Windows Embedded 8.1 I...
SQL Server 2012 Setup ...
SQL Server 2012 Report...
SQL Server 2012 SQL To...
Windows Forms Sample A...
Windows Live  Spaces: ...
MSDN and TechNet Searc...
MSDN, TechNet and Expr...
Orchard - Help and Sup...
WebsitePanel - Support
WebsitePanel - Develop...
MSDN Magazine
Microsoft Automatic Gr...
Bing Maps for Windows ...
SharePoint Server Prot...
Project Customization ...
Silverlight Installati...
Managed Extensibility ...
MVVM / ViewModel Patte...
Expression Design
Microsoft Online Syndi...
Windows Performance To...
Visual Studio Report C...
Axum Incubation Project
Commerce Server 2002 a...
DNS and Traffic Manager
Game Technologies: Dir...
Game Technologies: Gen...
(Retired) Exchange Pre...
Office Live Small Busi...
Parallel Computing Pla...
Phoenix
Popfly Bugs and Sugges...
Popfly Game Creator
Search Server: Feature...
Silverlight (formerly ...
Service Bus EAI & EDI ...
SQL Server 2014 SQL To...
SQL Server 2014 In Azu...
SQL Server 2014 Self-S...
SQL Server 2014 Analys...
SQL Server 2014 Master...
Team Foundation Server...
Tellme Studio (retired)
Tailoring your Windows...
Visual Basic Express 2...
Visual Basic Express E...
Visual C# 2008 (Pre-re...
Visual C# Express 2008...
Visual C++ IDE
Visual Studio Code Ana...
Visual Studio Team Sys...
WCF Data Services (Pre...
Web Sandbox - General
Windows Error Reportin...
Windows MultiPoint Mou...
Building Windows Store...
Windows Phone push not...
Windows Phone Preview ...

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile