Will 2 File System Watchers work in different threads concurrently? - vb.net

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

Related

How to explicitly call TIBDataSet.RefreshSQL

I have list of records in TIBDataSet (Embarcadero Delphi) and I need to locate and modify one record in this list. There is chance that underlying database record has been changed by other queries and operations since TIBDataSet had been opened. Therefor I would like to call RefreshSQL for this one record (to get the latest data) before making any changes and before making post. Is it possible to do so and how?
I am not concerned about state of other records and I am sure that the record under consideration will always be updated and those updates will be commited before I need to changes this record from TIBDataSet.
As far as I understand then RefreshSQL is used for automatic retrieve of changes after TIBDataSet has posted upates to database. But I need manual (explicit) retrieval of the latest state before doing updates.
Try adding a TButton to your form and add the following code to its OnClick handler:
procedure TForm1.btnRefreshClick(Sender: TObject);
begin
IBQuery1.Refresh; // or whatever your IBX dataset is called
end;
and set a breakpoint on it.
Then run your app and another one (e.g. 2nd instance of it) and change a row in the second app, and commit it back to the db.
Navigate to the changed row in your app and click btnRefresh and use the debugger to trace execution.
You'll find that TDataSet.Refresh calls its InternalRefresh which in turn calls TIBCustomDataSet.InternalRefresh. That calls inherited InternalRefresh, which does nothing, followed by TIBCustomDataSet.InternalRefreshRow. If you trace into that, you'll find that it contructs a temporary IB query to retrieve the current row from the server, which should give you what you want before making changes yourself.
So that should do what you want. The problem is, it can be thoroughly confusing trying to monitor the data in two applications because they may be in different transaction states. So you are rather dependent on other users' apps "playing the transactional game" with you, so everyone sees a consistent view of the data.

Running a block of code in the background of AppleScriptObjC app?

Is it possible to have a block of code constantly running or 'repeating' in AppleScriptObjC, whilst the rest of your script is still active? I've got a block of code that I want to repeat in the background that checks to see if a folder exists and creates it if it doesn't, but if I set it to repeat indefinitely then I lose the ability to access the other buttons and code blocks in my app?
Apologies if there isn't enough info here or it's a bit confusing!
I'd probably create a repeating NSTimer to do the check at a specified interval. That would avoid blocking your main thread.
Depending on the app, perhaps you could also just check for the existence of the folder and create it just in time, when you really have a need for it.

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.

How to close/stop a .NET application and re-execute it?

My application updates(running a vba script) an excel shared workbook, and since it is shared, there shouldn't be problems when someone else is using the same file at the same time. But for some reason, sometimes it simply freezes, without any error message, just freezes.
Is there a way to programatically make the application stops/closes automatically when frozen or after some minutes(In normal conditions, this updating process shouldn't take more than 1 minute)?
And, if possible, re-launch the app again automatically after some minutes for at least 5 attempts?
This way would ensure process completes succesfully.
I have had to do this same thing before but because I had an application that would look for updates to it's self on the network and then update it locally. Problem is, you cannot update the exe that is running.
What I did to get around it is to create another program that would wait a second, update the exe, then run the exe again.
Because I did this with a few different apps, I made my "Updater" generic so I could send some command line parameters and it would use those to copy and run.
If you want to try something else, you might be able to accomplish this same thing by creating a BAT file and running it. I'm not real good on BAT files so I can't help you there. But, it is another way to handle it.

How to override edit locks

I'm writing a WLST script to deploy some WAR's and an EAR. However, intermittently, the script will time out because it can't seem to get an edit lock (this script is part of a chain of many other scripts). I was wondering, is there a way to override or stop any current locks on the server? This is only a temporary solution, but in the interest of time, it will do for now.
Thanks.
You could try setting a wait period and timeout:
startEdit([waitTimeInMillis], [timeoutInMillis], [exclusive]).
Are other scripts erroring out, leaving the session locked? You could try adding exception handling around those. Also, if you have 'Automatically acquire lock" enabled in the Admin Console and you use the admin console sometimes it can cause problems if you are running scripts at the same time, even though you are not making "lock-requiring" changes.
Also, are you using the same user for the chained scripts?
Within WLST, you can pass a number as a parameter to gain an exclusive lock. This allows the script to grab a different lock than the regular one that's used whenever an administrator locks from the console. It also prevents two instances of the same script from stepping on each other.
However, this creates complex change merge scenarios that are best avoided (by processes).
Oracle's documentation on configuration locks can be found here.
Alternatively, if you want the script to temporarily relieve any existing locks regardless of the pending changes, you may as well disable change management from the console, minimizing the inconvenience caused.
WLST also contains the cancelEdit command that you could run before you startEdit. Hope one of these options pan out!
To take the configuration change lock from another administrator:
If another administrator already has the configuration lock, the following message appears: Another user already owns the lock. You will need to either wait for the lock to be released, or take the lock.
Locate the Change Center in the upper left corner of the
Administration Console.
Click Take Lock & Edit.
Make your configuration changes.
In the Change Center, click Activate Changes. Not all changes take
effect immediately. Some require a restart (see Use the Change
Center).
As long as you're running WLST as an administrative user, you should be able to jump into an existing edit session with the edit() command - I've done a quick test with two admin users, one in the Admin Console, and one using WLST, and it appears to work fine - I can see the changes in the Admin Console session inside the WLST interpreter.
You could put a very simple exception handler around your calls to startEdit that will log the exception's stack trace, but do nothing else. And then rely on the edit call to pop you into the change session.
Relying on that is going to be tricky though if another script has started an edit session and is expecting to be able to commit that change session itself - you'll be getting exceptions and unreliable behaviour across multiple invocations.