Are new instances of BackgroundTasks created each time they are run? - windows-8

When a BackgroundTask's Run method is called, can I ever rely on using state saved in the class's fields by previous calls to Run? If so, when?

I tested this for a TimeTrigger-triggered background task, and a new instance was created each time it was triggered and run.

Related

Will 2 File System Watchers work in different threads concurrently?

I have a service in vb.net and i am about to set another File system watcher. So i will have 2 in total.
One fswatcher triggers when there is a change in a certain file.txt, and the other one triggers when there is a change in a directory.
Each trigger goes to a different code method. So they do not collide(they dont share the same methods in the app).
So my question is, Is every fswatcher running in a thread?
So if i get two triggers will the code from fswatcher1 run in another thread than fswatcher2? Or will the one fswatcher wait for the other one to finish 1st?
Yes, though you can set the 'SynchronizingObject' property if you want enable locking mechanism between the two

Jbehave maintain global data across stories - for dependency/execution order

Problem:
Before running A.story and B.story the Procondition.story must be run and finished because Precondition.story inserts data in the database which is then used by A.sotry and B.story.
There are few approaches I know to set this dependency but they are not applicable in this context.
'Givenstories' annotation is not of much help because in this case Precondition.story will run twice, first time for A.story and second time for B.story which results Precondition.story failure second time saying the data which it tries to insert into the database already exist.
Using Maven failsafe plugin This will certainly place the Precondition.story on top in the execution list but all these stories are run in multi-threading environment where there are 8 threads ready to grab the stories to run simultaneously. Thread 1 takes the Precondition.story but while that story is yet not completed A.story and B.story kick off by thread 2 and 3 that makes A.story and B.story fail.
Specify the story order overriding storyPath(): Does not work due to the same problem mentioned in #2 above.
Possible solution: How about maintaining the state of the Precondition.story say in a boolean variable preconditionCompleted. When the Precondition.story completes the preconditionCompleted is set to true. Then add a step in A.story and B.story at the beginning which does polling on preconditionCompleted every seconds until it becomes true and then execute the rest of the story.
For this purpose I need to know where can we declare such global variables to use across stories?
you can use Singleton class, which will contain some object. This object can be locked in #BeforeStory method of Precondition.story and released in #afterStory. Then in A and B story in #BeforeStory methods, you can wait until this object is released and then execute them.
Another way that I can think of is to make custom order annotation, but then you need to create logic to process it.

Repeat a task with time delay in WinJS

I am developing an app in WinJS and I need to periodically run some tasks with a constant and specified delay between each pair of executions.
In particular, I am intending to update the user's position on the map every 30 seconds.
I am not quite sure how to implement the task scheduler in WinJS. I have looked at the background task class, but that doesn't seem to be much help in my case.
If Im reading this correctly and you simply want to do this while the application is running you just need a javascript timer - setTimeout.
note that with setTimeout you pass in the function itself without parenthesis, not a string name. Here's an app sample with a timer that updated the UI, although the main important takeaway here is that you need to make sure you call setTimeout again from within your 'update' function. Check out that code here
If you want some sort of background task to do this and generate a separate image (I dont think thats what you ant, but I'll include that since we're talking about tasks and delays)
If you are using Windows 8.1 (which releases soon) you can use the new scheduler class and pause and resume every 30 seconds as shown here
If you are using Windows 8 (and will work on 8.1) you can if I recall correctly setup your scheduled tasks every fifteen minutes and create one shot tasks for each 30 seconds within that time. run background task on timer

How to detect new processes

Is there a way to detect process starts (whena new program is run) without EnumProcesses or any other listing and comparing method. Is there an event based approach?

SQL script initializing a database for the first time

I am writing Web app. My program creates relations itself when it is needed, basically when the program is deployed and run first time. But I see that it is very common to create SQL script and run it to initialize data-base for the first time. Is it compulsory to do this?
No, it is not compulsory for the database initialization script to be part of the "first run" of your application; preparing the database can be a deployment step. In fact, depending how long it takes to initialize the database, you might specifically want to avoid initializing the database on the first run, and instead make sure it is deployed and initialized before the first time the application is accessed.