Opening 2 (or more) windows from one method to run 2 (or more) processes.

Hi Folks,

Another refactor request for input.

In a project from 2012, we open 2 or more windows depending on the users’ decisions to allow the same number of tasks to run on different data. This was always done via a thread that opened each window and then allowed that window’s process to run in conjunction with the other windows’ tasks. Under RS 2011r1 with a Carbon compile this worked properly for a number of versions and 100’s of users.

Jump forward to 2017 and 2 of the project’s larger installations are moving to 10.12-based Mac Minis and iMacs and we need to update the project to run in Cocoa as well as resolve the “ThreadAccessingUIExcetion” that the above description brings with it.

In my refactor plans, I changed the thread calls to use timers to open the separate windows as needed. However, it seems that no matter what order or how many wait loops I place before each new window.open call, one one of the windows opens and executes its take (the correct one does open, so the logic is passing the correct arguments to the correct window.

The other windows never open and debugging doesn’t answer the question as to what is happening.

The basic code for the process handler is:

For x = 0 To RunTask.Ubound
    tmTaskWindow(x).Mode = 1
Next

The tmTaskWindow timer is an array of timers allowing for up to 8 tasks to be started.

It’s really hard to say what is causing your problems without seeing your code.

I’d say you have 2 choices:

  • Do everything in a queue. Open one window, do the task. Open second window, do it’s task.
  • Open the 2 windows without doing anything. After the windows are open start the tasks.

I would also recommend that you solve the problem without your old code. Do a simulation task instead.

[quote=311777:@Beatrix Willius]Open the 2 windows without doing anything. After the windows are open start the tasks.
[/quote]
Thanks, Trixie. Since the tasks can run for days, it’s not “agreeable” to run them in a queue, this is what I’m trying to achieve. In my code, I set a flag that holds all until the task windows are all visible, and then they are supposed to start running. Pseudo code -

For x = 0 to numberoftasks
    openwindow(x)
next x
TaskReady = True

The windows should all be waiting for the TasksReady to become true, but something’s going sideways.