Very strange issue with showing a window?

Hey all,

I have a feature that is invoked from a menubar called “Backup Data”. This feature will save the database to a user specified location using a shell script. Sometimes, this database is very large, so rather than have the program just lock up, I want to display a little window that says “Backing Up…”. This all worked in older version of Xojo, but now I’m running the latest version, and I’m having a very strange problem. The backup window no longer shows up, UNLESS I display a MsgBox beforehand. See my code below:

dim w as new winBackingUp w.show s=new shell s.execute "cd "+f1.parent.shellPath+" && zip -r "+f2.shellPath+" "+replaceAll(f1.name," ", "\\ ") do until s.IsRunning=false loop w.close

This code used to work. But in the new Xojo it does not. The winBackingUp NEVER shows. I’ve tried many, many different tweaks and tests, but I cannot ever get it to show, UNLESS I add a debug MsgBox to the code. See code below:

dim w as new winBackingUp w.show msgBox "is window showing?" s=new shell s.execute "cd "+f1.parent.shellPath+" && zip -r "+f2.shellPath+" "+replaceAll(f1.name," ", "\\ ") do until s.IsRunning=false loop w.close

When I run that code, the MsgBox pops up, AND the winBackingUp window is showing. It works perfectly. But obviously I can’t have a MsgBox popping up. When I remove that MsgBox line, the winBackingUp window never shows.

This is driving me crazy. Anyone have any idea what’s going on here? Is it a bug in Xojo? I appreciate any help you can provide.

The operating system is trying to make the best use of resources. It won’t draw any windows until it has the opportunity to. Your code never releases execution time back to the window server to draw the window. The reason the MsgBox works is because the MsgBox is forcibly giving the window server a chance to draw.

It is not a bug in Xojo.

You need to make your code event driven. Not only will this make your window appear, it will improve the user experience as your app won’t seem to lock up. winBackingUp should have an asynchronous shell on it, which you can start in the Window.Open event. In the Completed event of that Shell object you can close the winBackingUp window.

I tried this, and it does work, however the issue is I also call the backupData method when the application is quitting, so there is a backup made every time the program is closed. When I use the event driven approach, even though I call w.showModal (which is supposed to freeze the method, in this case, app.close), the program just quits right away and the backing up window (with the shell) still never shows. And this is even worse — because the backup is never made.

The idea behind event driven programming is to free the user from terrible modal / locking design. Seriously, with the exception of just a few questions (like “are you sure you want to save changes?”), forget that ShowModal exists.

Here’s what I would do:
Use the App.CancelClose event to check whether the backup has occurred recently enough, cancel the close (the quit) if a backup is required, do the backup, and use the Completed event to store the new latest backup date and issue another Quit.

I will try that, thank you. It’s just strange that this used to work, and now doesn’t. Must be the fact that it worked before was the bug, and now it does not work because that bug was fixed.

+1. It should have never worked.