<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>DisplayFusion RSS: [BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</title>
<atom:link href="https://www.displayfusion.com/Discussions/RSS/?TopicID=018f8128-d494-75c1-8250-a3b0603a59a0" rel="self" type="application/rss+xml" />
<link>https://www.displayfusion.com/Discussions/RSS/?TopicID=018f8128-d494-75c1-8250-a3b0603a59a0</link>
<description>DisplayFusion RSS: [BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</description>
<lastBuildDate>Wed, 22 Apr 2026 22:26:14 GMT</lastBuildDate>
<language>en</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>https://www.displayfusion.com/Discussions/RSS/?TopicID=018f8128-d494-75c1-8250-a3b0603a59a0</generator>
<item>
<title>RE: [BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</title>
<link>https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#4</link>
<pubDate>Wed, 26 Jun 2024 13:46:10 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#4</guid>
<category>DisplayFusion</category>
<description><![CDATA[I spoke with our developers about this. We've adjusted the way DisplayFusion handles functions, and they run much faster now which is why it's overlapping, so this is working as it's supposed to.
Adding a delay like you did should help, and this might as well: https://www.displayfusion.com/Scrip...]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
I spoke with our developers about this. We've adjusted the way DisplayFusion handles functions, and they run much faster now which is why it's overlapping, so this is working as it's supposed to. <br/>
<br/>
Adding a delay like you did should help, and this might as well: <a href="https://www.displayfusion.com/ScriptedFunctions/Help/#bfsGeneralCountRunningFunctions" target="_blank" rel="nofollow"><b>https://www.displayfusion.com/ScriptedFunctions/Help/#bfsGeneralCountRunningFunctions</b></a>. You can check to see if that function is running, and if it's greater then 1, then close it.
</div>
]]></content:encoded>
</item>
<item>
<title>RE: [BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</title>
<link>https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#3</link>
<pubDate>Fri, 24 May 2024 02:49:24 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#3</guid>
<category>DisplayFusion</category>
<description><![CDATA[I didn't originally realize I could have state between calls. Thought the scripts were actually scripts & invoked in a sandbox or something.
In the meantime, since learning the static variables are stateful, I've added a queue + some caching to fix it.
Code
Copy
Select All
private static boo...]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
I didn't originally realize I could have state between calls. Thought the scripts were actually scripts & invoked in a sandbox or something.  <br/>
<br/>
In the meantime, since learning the static variables are stateful, I've added a queue + some caching to fix it. <br/>
<br/>
<div id="" class="col-md-12 BoxWrap"><div class="Box table-responsive"><a name="code" style="width:0; height:0;"></a><h2 class="TableTitle" style="border:0"><div class="TableTitleText">Code</div><div class="TitleButtons"><div class="TableTitleButton"><a href="#" onclick="return false;" data-clipboard-target="#code019db74d0fe772d1a4c44a6749d3962e" class="ClipboardCopyControl"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/clone.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;vertical-align:middle !important;width:auto;max-width:16px;height:16px;" /><span class="Text">Copy</span></a></div><div class="TableTitleButton"><a href="#" onclick="bfs.util.codeEditorSelectAll('code019db74d0fe772d1a4c44a6749d3962eJs'); return false;"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/square-check.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;vertical-align:middle !important;width:auto;max-width:16px;height:16px;" /><span class="Text">Select All</span></a></div></div></h2><div class="TableTitleContent table-responsive"><div class="AceEditorWrapper" style="border-top:solid 1px var(--color-default-border);padding:0"><pre id="code019db74d0fe772d1a4c44a6749d3962eJs" contenteditable="true" spellcheck="true" class="skiptranslate" style="width:100%; min-height:75px;">private static bool isBusy = false;
private static Queue&lt;IntPtr&gt; pendingHandles = new Queue&lt;IntPtr&gt;();

public static void Run(IntPtr windowHandle) {
    pendingHandles.Enqueue(windowHandle);
    if (isBusy) { return; }

    isBusy = true;

    if (Cache == null || Cache.MonitorCount != BFS.Monitor.GetMonitorCountEnabled()) {
        ResetCache();
    }

    while (pendingHandles.TryDequeue(out nint handle)) {
        try {
            ExecAction(handle);
        }
        catch (Exception e)
        {
            BFS.Audio.PlayWAV("U:\\Sounds\\notifications-wav\\Windows - Default Beep.wav");
            ResetCache();
        }
    }
    isBusy = false;
}

record CachedData(int MonitorCount, Rectangle PrimaryArea, Rectangle[] WorkAreas, Rectangle[][] SubAreas, Rectangle[] SubDivisions);

private static CachedData Cache = null;

private static void ResetCache() {
    int count = BFS.Monitor.GetMonitorCountEnabled();
    var primary = BFS.Monitor.GetPrimaryMonitorWorkArea();
    var workAreas = BFS.Monitor.GetMonitorWorkAreas();
    if (CycleLeft) { Array.Reverse(workAreas); }
    var subareas = workAreas.Select(static x =&gt; x.GetSubdivisions()).ToArray();
    var subdivs = subareas.SelectMany(static x =&gt; x).ToArray();
    Cache = new CachedData(count, primary, workAreas, subareas, subdivs);
}</pre><textarea id="code019db74d0fe772d1a4c44a6749d3962e" name="code019db74d0fe772d1a4c44a6749d3962e" style="position:absolute; top:0; left:-999999px; width:1px; height:1px;"></textarea></div>
</div></div></div><br/>
It's made it painfully obvious how slow something has gotten though. <br/>
Takes almost a second (probably closer to 750ms) or so to move one spot.
</div>
]]></content:encoded>
</item>
<item>
<title>RE: [BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</title>
<link>https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#2</link>
<pubDate>Fri, 17 May 2024 14:12:33 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0#2</guid>
<category>DisplayFusion</category>
<description><![CDATA[I was able to reproduce that here so I've added it to our list to look into.
Thanks!]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
I was able to reproduce that here so I've added it to our list to look into.<br/>
<br/>
Thanks!
</div>
]]></content:encoded>
</item>
<item>
<title>[BUG]: Scripted Functions can be re-called before previous invocation complete, causing them to conflict</title>
<link>https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0</link>
<pubDate>Thu, 16 May 2024 11:28:08 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/bug-scripted-functions-can-be-re-called-before-previous-invocation-complete-causing-them-to-conflict/?ID=018f8128-d494-75c1-8250-a3b0603a59a0</guid>
<category>DisplayFusion</category>
<description><![CDATA[I can't recall this being an issue prior to DisplayFusion Pro 11.0 Beta, but it's been a problem for multiple betas now.
The function "Cycle Left to Unoccupied Position"  is a function I submitted some time ago & have been running for years.  It splits horizontal monitors to 4 quadrants & vertic...]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
I can't recall this being an issue prior to DisplayFusion Pro 11.0 Beta, but it's been a problem for multiple betas now.  <br/>
<br/>
The function <a href="https://www.displayfusion.com/ScriptedFunctions/View/?ID=94b97dcb-1d10-4c69-9a9e-776d61daaa4d" target="_blank" rel="nofollow"><b>"Cycle Left to Unoccupied Position"</b></a>  is a function I submitted some time ago & have been running for years.  It splits horizontal monitors to 4 quadrants & vertical monitors to top and bottom quadrants. When choosing the next quadrant to cycle to it first checks if there's already an instance of the same program occupying that area, and if so, move on to the next. <br/>
<br/>
My monitor configuration and quadrants is like so: <div class="Image"><a href="https://i.imgur.com/pj19zyZ.png" target="_blank" data-fancybox="" data-caption="https://i.imgur.com/pj19zyZ.png" HelpButtonData="https://i.imgur.com/pj19zyZ.png" HelpButtonDataAlign="BelowMiddle"><img src="https://i.imgur.com/pj19zyZ.png" alt="https://i.imgur.com/pj19zyZ.png" title=""></a></div><br/>
<br/>
It has recently, I believe with the beta, become problematic.  <br/>
<br/>
As far as I can tell & what I believe is happening, is some change made things slow. SO now when it's rapidly called to move a window serveral positions, it's being invoked before the prior invocation has exited, & they end up fighting.  <br/>
The action was once instantaneous so I would rarely, if ever, experience this issue.  With that no longer the case, an attempt to cycle a window across all 4 monitors causes the window to throw an epileptic fit. To move a  window furthest monitor left to furthest right requires 3 invocations if maximized, otherwise takes 5-9 invocations. However because the function has wrap around, a variant to cycle the opposite direction, and cycles maximized windows by monitor instead of quadrant, typically only 2-4 invocations are needed to position windows where needed. <br/>
<br/>
Either whatever slowed down needs fixing, or a guard preventing concurrent invocations of a function on the same window.<br/>
<br/>
Screen capture of the issue:   <br/>
<a href="https://i.imgur.com/UPBaNEV.gif" target="_blank" rel="nofollow"><b>https://i.imgur.com/UPBaNEV.gif</b></a><br/>
<br/>
Same thing except mp4 & uploaded to you guys instead of imgur:<br/>
<div class="Image"><a href="https://www.displayfusion.com/Discussions/Download/?ID=018f8128-d65e-7662-bc33-1617cb2e7275" target="_blank" data-fancybox="" data-caption="https://www.displayfusion.com/Discussions/Download/?ID=018f8128-d65e-7662-bc33-1617cb2e7275" HelpButtonData="https://www.displayfusion.com/Discussions/Download/?ID=018f8128-d65e-7662-bc33-1617cb2e7275" HelpButtonDataAlign="BelowMiddle"><img src="https://www.displayfusion.com/Discussions/Download/?ID=018f8128-d65e-7662-bc33-1617cb2e7275" alt="https://www.displayfusion.com/Discussions/Download/?ID=018f8128-d65e-7662-bc33-1617cb2e7275" title=""></a></div><br/>
<br/>
Also FYI, often I'll find 1 or two instances of the function in the system tray that are stuck running.  Not sure what condition would cause them to continuously run. These stuck "running" instances don't appear to effect anything.
</div>
]]></content:encoded>
</item>
</channel>
</rss>