Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all
I've got a function that triggers on USB disk insertion.
Action depends on disk, but if i plug 2 USB devices in a short time, the second one is skipped as my function
is in use.
So, how to:
1) Have function trigerred by USB (this one works, thanks for prior help in forum)
2) The trigger function (OnUSB) do an action in a separate function DoAction, making itself available for another USB, even if DoAction is not ended
3) upon insertion of second device, either OnUSB queues the event, either it can fire DoAction function in a separated thread independent..
Other words : OnUSB can fire async DoAction function on trigger, or queue them
Thanks
Posts: 12,090
Threads: 142
Joined: Dec 2002
If several instances of DoAction can run simultaneously, let OnUsb start it in separate thread: mac "DoAction".
Else if DoAction is macro, try Properties -> Macro properties -> If a macro is running -> Enqueue.
Else, start DoAction in separate thread and insert lock at the beginng of DoAction.
Posts: 795
Threads: 136
Joined: Feb 2009
Quote:If several instances of DoAction can run simultaneously
Exactly what i want
Quote:let OnUsb start it in separate thread: mac "DoAction"
Will try.
Quote:if DoAction is macro, try Properties -> Macro properties -> If a macro is running -> Enqueue
Seems quick and dirty, is it reliable enough (some triggers can be very close in time and DoAction
must enqueue many tasks in few seconds)
Quote:start DoAction in separate thread and insert lock at the beginng of DoAction
Was my first try, but if successive calls are not enqueued, hopeless.
Is it the same from shell menu, i can handle many files in different folders via a function
launched from shell menu trigger. The first one always blocks later calls to it.
Posts: 12,090
Threads: 142
Joined: Dec 2002
In your case probably better is function, not macro.
Quote:The first one always blocks later calls to it.
Look in Properties, maybe 'single instance' checked.
If multiple threads started but interfere with each other, use lock, then other threads wait until first thread ends or unlocks.
Posts: 795
Threads: 136
Joined: Feb 2009
Quote:Look in Properties, maybe 'single instance' checked.
Yes it was the culprit, nice done.
I must do something wrong, because I modified a shell menu trigger function from:
foreach f files
FCleanthefile(f)
to
foreach f files
mac "FCleanthefile" "" f
I can now launch several FCleanthefile function separatly (what i was looking for)
and the results are not the same, ie the files are not properly cleaned in latter function, why?
Posts: 12,090
Threads: 142
Joined: Dec 2002
I don't know what FCleanthefile does.
Posts: 795
Threads: 136
Joined: Feb 2009
It's a function calling external program to clean mp3 tags, f is the file argument to be processed. At the end, only album, title and genre tags should remain. (it's a dBpoweramp command line tool FYI)
It's doing it's job when used directly (FCleanthefile(f))
but some tags are not deleted when called by mac : mac "FCleanthefile" "" f, ie some tags are still present in file (comment, artist etc).
Posts: 12,090
Threads: 142
Joined: Dec 2002
Why need to launch several FCleanthefile function separatly?
Posts: 795
Threads: 136
Joined: Feb 2009
Because I use a shell menu trigger to clean files in several folders, and select files I want to clean by navigating different folders,
and want the job begin before I do each folder one after the other;
I go folder A, launch clean files process, go folder B, launch another cleaning process and so on.
Only the mac FCleanthefile "" "f" allows that, the FCleanthefile(f) way requires to do folder B after folder A
cleaning is totally finished.
Posts: 12,090
Threads: 142
Joined: Dec 2002
Better convert the main macro to function, and let it simply call FCleanthefile, not with mac.
Posts: 795
Threads: 136
Joined: Feb 2009
Wonderful, it was simple as converting a macro to function....
Anyway, it does not explain why the different calls give different result in the command line exe...
Can you in few words explain what converting to a function did the job, would help to understand.
Posts: 12,090
Threads: 142
Joined: Dec 2002
Quote:Anyway, it does not explain why the different calls give different result in the command line exe...
It still happens now? Maybe the command line program does not support multiple instances of its process. Then add lock near the beginning of the shell-menu-triggered function.
function $files
lock ;;other thread will wait here until previous thread ends. It is a simple way to make threads run in a queue, not simultaneously. Actually it's not a true queue, eg if launched thread 1, 2 and 3, may run 1, 3 and 2.
foreach f files
,FCleanthefile(f)
Quote:Can you in few words explain what converting to a function did the job, would help to understand.
When it was macro, it did not run if previous instance of the macro was still running. Now two threads of the function run simultaneously in this case; and two processes of the command line program launched, unless there is lock .
Posts: 795
Threads: 136
Joined: Feb 2009
Quote:It still happens now? Maybe the command line program does not support multiple instances of its process. Then add lock near the beginning of the shell-menu-triggered function.
I put the lock in another place, but yours makes it do the job. Sometimes, I wonder why I struggle so much
with little details problems....
Quote:When it was macro, it did not run if previous instance of the macro was still running. Now two threads of the function run simultaneously in this case; and two processes of the command line program launched, unless there is lock .
Will use more functions than macros, seems more flexible..
thanks again.
|