How to Write From one Thread to Another ?
12 posts
• Page 2 of 2 • 1, 2
Re: How to Write From one Thread to Another ?
PGilbert wrote:Found it:∇Dispatch[⎕]∇
[0] obj Dispatch action;ActionObj;delegate;⎕USING
[1]
[2] action←⎕OR ⎕FX'RunBackground'action
[3]
[4] ⎕USING←'System,System.dll' 'System.Windows.Threading,WindowsBase.dll'
[5]
[6] {}obj.Dispatcher.BeginInvoke(DispatcherPriority.Normal(⎕NEW Action action))
⎕USING ← 'System.Windows,WPF/PresentationFramework.dll'
win ← ⎕NEW Window
win Dispatch& 'win.Title←''hello world'''
win.Title
hello world
The problem that I see is that all actions will be put into the same function named 'RunBackground' and if you do a couple of rapid Dispatch one after each one the 'RunBackground' executed may not be the good one.
Is there a way to fix this ?
Hi Pierre,
I've tried the above code, but I don't see the problem that I think you are describing. Are you able to send a small repro showing "the 'RunBackground' executed may not be the good one."?
Thanks,
John Daintree.
-
JohnD|Dyalog - Posts: 74
- Joined: Wed Oct 01, 2008 9:35 am
Re: How to Write From one Thread to Another ?
Hello John, the code by itself is working fine. It is just that the 'RunBackground' function that is created to run is not 'unique' and if another 'Dispatch' is fired when the first one is not finish to run than it may interfere with the good operation of the program.
My solution is to add to the name of 'RunBackground' a timestamp in characters like this: (⍕⎕TS)~' ' ,that will make each 'RunBackground' function 'unique'. Looks like also that a function can erase itself with ⎕EX on the last line, so it will erase itself when finished. The final result looks like this:
Is this the right way to do it or there is a better way ?
Thanks in advance.
My solution is to add to the name of 'RunBackground' a timestamp in characters like this: (⍕⎕TS)~' ' ,that will make each 'RunBackground' function 'unique'. Looks like also that a function can erase itself with ⎕EX on the last line, so it will erase itself when finished. The final result looks like this:
∇Dispatch[⎕]∇
[0] obj Dispatch action;⎕USING;dispatchName
[1]
[2] dispatchName←'RunBackground_',(⍕⎕TS)~' '
[3]
[4] action←⎕OR ⎕FX dispatchName action ('⎕EX ''',dispatchName,'''')
[5]
[6] ⎕USING←'System,System.dll' 'System.Windows.Threading,WindowsBase.dll'
[7]
[8] {}obj.Dispatcher.BeginInvoke(DispatcherPriority.Normal(⎕NEW Action action))
Is this the right way to do it or there is a better way ?
Thanks in advance.
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
12 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group