MS Workflow problem with custom activities member variable state - workflow

I have a simple custom activity with a private member variable (integer).
When i put it inside a sequence activity which is inside a while activity and start iterating i have a problem:
My member variable is zeroed in each iteration even though i increment it by one every time the activity is executed.
What am i doing wrong?
Thanks,
Adi Barda

Without seeing the code it is hard to say, but when you are working inside of a While activity you have to be careful how you modify state on your child activities. The While activity spawns multiple execution execution contexts and will clone your activity from a template (in other words - you aren't executing the same activity multiple times, the workflow creates multiple instances of your custom activity). See: http://blogs.msdn.com/advancedworkflow/archive/2006/03/21/557121.aspx and http://msdn.microsoft.com/en-us/magazine/cc163414.aspx

Related

How to fetch foreach activity output to until activity

I'm new to work with data factory. I want to know how can I fetch ForEach activity's inner activity result from outer Until activity. I have my pipeline as below.
My ForEach1 activity looks like this,
My until activity looks like this.
I want to fetch Azure Function activity's output from Web activity, but pipeline is failing with the error "ErrorCode=InvalidTemplate, ErrorMessage=cannot reference action 'Log_extraction_func_copy1'. The action 'Log_extraction_func_copy1' is nested in a foreach scope of multiple levels. Referencing repetition actions from outside the scope is supported only when there are no multiple levels of nesting". Is there any way out for this? Sorry, I'm not good at English.Hope my question is clear.
You can assign the output of function in a variable using set variable and access the variable value from web activity.

Delay from a Database in a custom flowchart

I would like to use my custom flowchart for different process flows and the delay time of my process is coming from a database. I tried to use the parameter but doesn't work. How can I get access to my database and connect it with my delay block in my custom flowchart to get my delay from the dbase. My target is to pick my pallets from the racks to the certain times.
delaytime =timearrival_minutes
Use a DynamicEvent.
Create a function at the model start that loops across all dbase entries. Create a dynamic event for each entry that is triggered by "the dbase-entry date" minus "your current model start date".
In the Dynamic Event, trigger rawMaterialStorage.free(some agent), obviously it is up to you to free from the correct custom block.
Check example models and the help on looping dbase entries and Dynamic Events :)

How to identify the multi-instance sub-process and differentiate it from the main process in Jbpm?

I have used one multi instance subprocess which includes an workflow with human task. When executing, its creating the number of human tasks as to the number of elements present inside the collection object. But all tasks have same process instance id. How the relation is working between parent process and multi instance subprocess?
If there are multiple elements in collection list, then it will create those many tasks inside the multi instance sub process. As all the tasks have same process instance id, how to identify the respective process variable values for each task and the uniqueness of each flow afterwards? And is there a way to make it create an different instance id for each task of the multi instance subprocess?
I did not get all the question, but I will try to answer what I got:
Human tasks have their own task instance id
What is collection object? If you mean tasks in bpmn model, then it is as expected: process instance flow starts after start node and when it reaches a human task, it will create an task instance with id. You can see it in the tasks in UI and with api you can claim, work on, complete , populate data etc.
it is wise to have a separate/different variable for every tasks that can execute in parallel. Then the input will be kept in distinguished data placeholders and you can use it accordingly.
you can create a different instance(task instance) for each task or have repeatable tasks
well the answer was to put the multi-instance into a sub-process, this will allow me to have a separate process instance id per each element of the my List (the input of the multi-instance )

dispatch_queue_create multiple invocations with same label

I have a requirement to execute a small set of related tasks on a custom thread created for them. The tasks will be scheduled from different classes.
I'm planning to use GCD's dispatch_queue_create to create the custom thread and schedule the task on it. Note that all the related tasks must execute only on that one thread in order.So my question is if I call dispatch_queue_create("my_custom_thread_label", NULL) with the same label from many classes in my codebase, would it all eventually map to just one thread? Or do I need to create it in one place and get a reference to it whenever needed? Thanks.
You need to create it in one place and pass the pointer around.

How can I use a property on my Job instead of JobDataMap dictionary in Quartz.NET?

I am working on a Windows service which needs to schedule tasks whenever one of it's web services is called. This could happen hundreds of times per second in a worst case scenario. The task needs to wait a period of time, typically a minute or two, then call a method passing a parameter.
We tried to build our own scheduler class to do this:
public void ScheduleTask<T>(TimeSpan delay, Action<T> task, T arg)
{
Thread.Sleep(delay);
threadPool.ExecuteAsync(task, arg);
}
But we figured this wouldn't be appropriate because we could theoretically end up with hundreds of Thread Pool threads all waiting. I am under the impression that there is a finite number of Thread Pool threads available and that this could potentially lock up the system.
I then turned to Quartz.NET and read on their features page that:
Job class instances can be instantiated by Quartz.NET, or by your application's framework.
and on page 3 of their tutorial that the Scheduler creates instances of your Job class (not you) and as such:
it does not make sense to have data-members defined on the job class as their values would be 'cleared' every time the job executes.
Feel free to yell at me, but how do I get a reference to my Job class instance before it executes so I can set a property on it?
The property is doing the job of a
parameter so i have no interest in it
after the Job has executed.
I also want to minimise the number of
objects it takes to acheive this to
keep my code neat and simple.
Finally, I seriously dislike using
Dictionaries so would prefer to avoid the JobDataMap object.
I don't understand exactly what your use case is and why you would need to set a property on the job, but to answer your question: to get access to your job before it executes you need to create a job listener (implement IJobListener). The job listener gets called just before the job gets executed, so you could set a property at that point.
Some links:
The documentation on job listeners
I wrote a blog post detailing the creation of listeners, here.