host a windows workflow problem

C

Claudia Fong

Hi

I was using a console application to host the windows workflow and when
I change to winforms, I don't know how to do it...

I pass the parameters into the workflow from the winform and is work
fine, but I try to output something from my workflow to the winform
that's when the problem arise...

I know that I can write this code line in my workflow code so I can
display a message box in the winform:

System.Windows.Forms.MessageBox.Show("Hello");

but is it possible for write a code in workflow to add something inside
the listBox?

I want something like listBox1.Items.Add(variablename);


Cheers!

Claudi
 
M

Michael Nemtsev

Hello Claudia,

It's possible, everything you need to do is to set your form to the workflow
- and I think you should never do this.
What's wrong with the event-based approache?!
WF is another level of abstraction, which shound know nothing about your
UI, it's the business logic which works with entities - not the UI controls.

It's directly the UI job to get the info from WF and show it

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

CF> Hi
CF>
CF> I was using a console application to host the windows workflow and
CF> when I change to winforms, I don't know how to do it...
CF>
CF> I pass the parameters into the workflow from the winform and is work
CF> fine, but I try to output something from my workflow to the winform
CF> that's when the problem arise...
CF>
CF> I know that I can write this code line in my workflow code so I can
CF> display a message box in the winform:
CF>
CF> System.Windows.Forms.MessageBox.Show("Hello");
CF>
CF> but is it possible for write a code in workflow to add something
CF> inside the listBox?
CF>
CF> I want something like listBox1.Items.Add(variablename);
CF>
 
N

Nicholas Paldino [.NET/C# MVP]

Claudia,

The workflow is being processed on a thread that is not the UI thread.
When you receive a notification from the workflow and you want to interact
with the UI, you will need to call the Invoke method on a form/control in
the UI and then pass a delegate that will do the work that you want to have
performed on the UI thread.

Hope this helps.
 
V

verbiest

Claudia,

The workflow is being processed on a thread that is not the UI thread.
When you receive a notification from the workflow and you want to interact
with the UI, you will need to call theInvokemethod on a form/control in
the UI and then pass a delegate that will do the work that you want to have
performed on the UI thread.


It's even better to call the 'BeginInvoke'-method because the 'Invoke'-
method may lead to deadlocks.

See here: http://kristofverbiest.blogspot.com/2007/02/avoid-invoke-prefer-begininvoke.html

regards,

Kristof Verbiest
 

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