index > Windows Workflow Foundation > Problem opening new window from a workflowCompleted event handler

Problem opening new window from a workflowCompleted event handler

I am trying to open a new window once a workflow is completed. I am using the following code:

public void InizializeFlickrPhotosGetSizesWorkflow(string photoId, string title, ImageSource image, string description, string tags)
{
parameters =
new Dictionary<string, object>();
parameters.Add(
"PhotoId", photoId);
try
{
if ((this.workflowRuntime = new WorkflowRuntime()) == null)
{
throw new System.Exception("There was a problem creating the workflow runtime.\nThe Application will now exit.");
}
else
{
// Add the External Data Exchange Service
ExternalDataExchangeService dataService =
new ExternalDataExchangeService();
// Add dataService to the workflow runtime
this.workflowRuntime.AddService(dataService);
//Add GetLiveSearchKey to the dataService
dataService.AddService(new FlickrAPI.FlickrKeys());
}
}
catch (System.Exception ex)
{
System.Windows.
MessageBox.Show(ex.Message.ToString());
}
this.instance = workflowRuntime.CreateWorkflow(typeof(FlickrActivityLibrary.FlickrPhotosGetSizes), parameters);

this.workflowRuntime.WorkflowCompleted += delegate(object s, WorkflowCompletedEventArgs ex)
{
Thread newWindowThread = new Thread(delegate()
{
previewPhotoWindow=
new PhotoView(int.Parse((ex.OutputParameters["LargeHeight"] as String)), int.Parse((ex.OutputParameters["LargeWidth"] as String)), title, image, description, tags);
previewPhotoWindow.Show();

}
);
newWindowThread.SetApartmentState(
ApartmentState.STA);
newWindowThread.Start();
parameters.Clear();
waitHandle.Set();
};

workflowRuntime.WorkflowTerminated += delegate(object s, WorkflowTerminatedEventArgs ex)
{
System.Windows.
MessageBox.Show("WorkflowTerminated");
Console.WriteLine(ex.Exception.Message);
parameters.Clear();
waitHandle.Set();
};
}

Once the new window should be shown (the line in bold), I get the following error:

LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Any ideas why I get this error message? Any help is welcome...

markovuksanovic

Hi;

I thought it was a threading problem so I went through writting similar code as the one you have. As you may know each workflow instance is running on a separate thread. However, I got nothing and no exceptions.

I think the problem you have is having exception in the first line where you create the new window and passing some data to the newly created window.




Ahmed Nagy
Ahmed Nagy

I solved the problem with opening a new window using dipatcher:

OpenWindowDelegate openWindowDelegate = new OpenWindowDelegate(this.OpenWindow);

this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, openWindowDelegate, previewPhotoWindow, int.Parse((ex.OutputParameters["LargeHeight"] as String)), int.Parse((ex.OutputParameters["LargeWidth"] as String)), title, image, description, tags);

And there was one more problem as well,.... loading image into WPF image object which I also had to update using dispatcher.... The problem is that I don't understan why the above code worked and trying to open a new window without a dispatcher resulted in a loaderLock?

markovuksanovic
reply 3

You can use google to search for other answers

 

More Articles

• Inspecting a State Machine Workflow
• Runtime Engine Durability
• Transaction Requires a Persistence Service?
• Problem in running hands on lab 5
• Workflow for Ticket System
• SQLTracking and Persistence
• SQL Persistence, Loading Workflows and Workflow Properties
• Equivalent Keyword for IRootActivity in beta2
• Workflow and queues
• No templates show after installation of WWF
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Beta2 - CallExternalMethod vs InvokeMeth
• Deserialization in while loop
• Can DataExchange service hold variables?
• run workflow xoml from asp.net
• WWF Scalabilty
• HowTo make a StateMachine Workflow wait
• Event cannot be delivered
• Issues in installing Windows workflow fo
• Workflow aborted with SqlWorkflowPersist
• Creating a workflow instance using a com
• WorkflowPersistence simple question
• ValidationOptionAttibute
• How to get ActivityExecutionContext from
• Beta2: String-Properties in Custom Activ
• Error with custom activities

Hot Articles

• Can you get the current state of a State
• How to display a Workflow in a Avalon Ap
• FlowChart workflow - Custom FreeformActi
• Deriving, CodeConditions and HandleExter
• Restarting persistent worklow throws a m
• Bug? Removing UI type editors on paramet
• Trouble with WebService and Persistence
• navigate page/forms?
• Developing on Windows XP SP2
• How stable is the current Beta 1?
• Designer embedded in ASP.NET page
• Getting started with WinWF and ASP.NET
• SqlWorkflowPersistenceService and SqlTra
• adding dynamic properties to custom Acti
• Dynamic workflow and workflow instance.

Recommend Articles

• WorkflowXSDGenerator Issues?
• Where to get July CTP of .NET Framework
• Unit Testing with Team Foundation
• sync vs. async
• Re-creating Event-listener after Runtime
• Parallel Split / Sync
• Stepping around in a workflow and buildi
• clarification: correlation to the instance
• Advice on where to begin
• WWF Scalabilty
• a Beginner Cuestion...
• Microsoft Sharepoint Workflow(7 Files).zip
• Where to start ....
• Example of SQL persistance service
• why are all the designers internal sealed?