Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
-
Recent Posts
Archives
Categories
Meta
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
If you wondered why all your states were stacked on each other when rehosting the workflow designer, here is what you need to do.
The workflow designer saves the layout information in a .layout file corresponding to the workflow file. ( StateMachineWorkflow1.xoml or StateMachineWorkflow1.cs will have a StateMachineWorkflow1.layout generated by the VS workflow designer).
When rehosting the state machine workflow, in your rehosting app, use a derived WorfklowDesignerLoader instead of the base and inside PerformLoad() call LoadDesignerLayout() and point the xml reader to your layout file.
LoadDesignerLayout(XmlReader layoutReader, out IList layoutLoadErrors)
alternatively if you are loading the workflow from a compiled assembly you could use this method
LoadDesignerLayoutFromResource(Type type, string manifestResourceName, out IList errors)
Recently I came across a request for a workaround the STAThread problem from a customer. He wanted to show a Save file dialog from within a CallExternalMethod activity. Since this thread is owned by the workflow instance there is no way to set the apartment state of this thread to ApartmentState.STA. This snippet works around the problem. ( Although In general using block UI elements like this inside of workflows is not recommended)
string fileSavePath;
Thread newThread = new Thread(delegate()
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
fileSavePath = saveFileDialog.FileName;
}
}
});
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
newThread.Join();