Workflow problem


G

Gilbert Tordeur

Hello.

Context = VB 2008

I am a beginner in using WF. I try to make the samples explained in the
French version of the book Microsoft Windows Foundation Step by Step. But I
try to translate C# to VB because VB is the language I use for programming.

I have build a solution with 2 projects (chapter 3 in the book) :
1) The main project is WorkflowHost, containing the main module and a
WorkflowFactory class.
2) The other project is LongRunningWorkflow, defining the sequential
workflow (a first message, a 10s wait time and a second message).

At execution, both message boxes are displayed correctly, but instead of
receiving 4 console messages :
Waiting for workflow completion.
Workflow instance idled.
Workflow instance completed.
Done.

only the first two are displayed, then nothing (and the program does not
stop).

The code is below. Where is the error ?

Thank you for your help,
Gilbert

PS. When translation a C# line
workflowRuntime.WorkflowIdled += new
EventHandler<WorkflowEventArgs>(workflowIdled);
in VB I have not taken <WorkflowEventArgs> into account (because I do not
know). Is this a problem?

Imports System.Threading

Imports System.Workflow.Runtime

Module Module1

Private _waitHandle As New AutoResetEvent(False)

Sub Main()

Dim Wfr = WorkflowHost.WorkflowFactory.GetWorkflowRuntime

AddHandler Wfr.WorkflowIdled, AddressOf workflowIdled

AddHandler Wfr.WorkflowCompleted, AddressOf workflowCompleted

AddHandler Wfr.WorkflowTerminated, AddressOf workflowTerminated

Console.WriteLine("Waiting for workflow completion.")

Dim Wfi = Wfr.CreateWorkflow(GetType(LongRunningWorkflow.Workflow1))

Wfi.Start()

_waitHandle.WaitOne()

Console.WriteLine("Done.")

End Sub

Sub workflowTerminated(ByVal sender As Object, ByVal e As
WorkflowTerminatedEventArgs)

Console.WriteLine("Workflow instance terminated, reason: '{0}'.",
e.Exception.Message)

_waitHandle.[Set]()

End Sub

Sub workflowCompleted(ByVal sender As Object, ByVal e As
WorkflowCompletedEventArgs)

Console.WriteLine("Workflow instance completed.")

_waitHandle.[Set]()

End Sub

Sub workflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs)

Console.WriteLine("Workflow instance idled.")

End Sub

End Module

======================

Imports System.Workflow.Runtime

Namespace WorkflowHost

Public Class WorkflowFactory

' Singleton instance of the workflow runtime

Private Shared _workflowRuntime As WorkflowRuntime = Nothing

' Lock (sync) object

Private Shared _syncRoot As New Object()

' Factory method

Public Shared Function GetWorkflowRuntime() As WorkflowRuntime

' Lock execution thread in case of multi-threaded

' (concurrent) access.

SyncLock _syncRoot

' Check for startup condition

If IsNothing(_workflowRuntime) Then

' Not started, so create instance

_workflowRuntime = New WorkflowRuntime()

' Provide for shutdown

AddHandler _workflowRuntime.WorkflowCompleted, AddressOf StopWorkflowRuntime

AddHandler _workflowRuntime.WorkflowTerminated, AddressOf
StopWorkflowRuntime

' Start the runtime

_workflowRuntime.StartRuntime()

End If

' Return singleton instance

Return _workflowRuntime

End SyncLock

' lock

End Function

' Shutdown method

Shared Sub StopWorkflowRuntime(ByVal sender As Object, ByVal e As EventArgs)

If Not IsNothing(_workflowRuntime) Then

If _workflowRuntime.IsStarted Then

Try

' Stop the runtime

_workflowRuntime.StopRuntime()

' Already disposed of, so ignore...

Catch generatedExceptionName As ObjectDisposedException

End Try

End If

End If

End Sub

End Class

End Namespace

==================

Imports System.Windows.Forms

Public Class Workflow1

Inherits SequentialWorkflowActivity

Private Sub PreDelayMessage(ByVal sender As System.Object, ByVal e As
System.EventArgs)

MessageBox.Show("PreDelay")

End Sub

Private Sub PostDelayMessage(ByVal sender As System.Object, ByVal e As
System.EventArgs)

MessageBox.Show("PostDelay")

End Sub

End Class
 
Ad

Advertisements

M

Mr. Arnold

Gilbert Tordeur said:
PS. When translation a C# line
workflowRuntime.WorkflowIdled += new
EventHandler<WorkflowEventArgs>(workflowIdled);
in VB I have not taken <WorkflowEventArgs> into account (because I do not
know). Is this a problem?

It's possible. And you need to figure out how to convert it to VB.

The WF events you are looking to firer are not firing..

I sugget you get a book that's going to show you in VB how to use WF.

http://apress.com/book/view/9781590597187


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4504 (20091013) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Ad

Advertisements


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

Top