Open show dialog in a thread

Can someone show me how to open a window using the showdialog in a thread? I have messed around with this for a long time and just don’t understand the LR or examples enough to understand how to do this. Maybe have an example I can review?

The idea is that threaded work doesn’t touch the interface. If you have to interact with the user, set it up before starting the thread.

What exactly are you trying to do?

Use a Timer.

Add a Timer to a global module (or in App.Open) and create a method that you use in the timer’s Action event via AddHandler.

In A global module, add a global property:

tmOpenMyWindow As Timer

In App.Open, add:

tmOpenMyWindow = New Timer tmOpenMyWindow.Mode = 0 tmOpenMyWindow.Period = 1 AddHandler tmOpenMyWindow.Action, AddressOf mOpenMyWindow

*** NOTE: Do NOT place parenthesis around the parameters to AddHandler … ***

Create a method named “mOpenMyWindow(Sender As Timer)” that simply calls:

wMyWindow.Show

Then, in the thread call “tmOpenMyWindow,Mode = 1”

Hi Tim P. I am trying to open a window, select files/folder from that window and then fill a listbox with the Full Path, File Name, size, etc… on a Mac.

Hi Tim J. Let me play around with the example you sent and see if I can get it to work. Thanks.

Open the dialog and get the files prior to starting the thread.
If you’re doing nothing more than listing the files in the Listbox you don’t really need a thread.

If you’re processing the files in some way, you can use he new Thread update UI method/event in API 2 to display results in the Listbox after each file gets processed.

Tim P. You understand my predicament very well and this is where I need a little guidance. I have a push button that initiates the show dialog box to select the files/folders and then processes the selected files to create various hash values and populates the listbox with the data about the files. I just need to know how to separate the two and make the population of the listbox occur using a thread or timer.

When ever i have threads i create a message queue between the thread and the app.
The app (using a timer) polls the message queue for ‘events’.
You define these events and the data structures in the queue as an IPC spec.

I have also used interfaces to communicate between threads and main line this also works.

I’ve written code like this. When the thread needs to show an Open dialog, the thread calls out to a timer, which creates and opens the dialog and returns the results. The thread simply idles while it waits for the results to come in.

Pseudo-code example:


Window
     public gResult as integer
     public gFile as folderItem


Thread1.Run()
   ...
  ' time to get a folderItem
  ' we can't do UI stuff in a thread, so we have to call out to a Timer on the main thread
  gResult = 0 
  TimerGetFiles.Mode = 1 
  while result = 0  // result is a global
    Sleep(100)
   wend
  switch gResult 
  case -1:
       return // user canceled
   case 1: 
        dim f as folderItem = gFile // get the folderItem
       ... do somtehing
  end select
  ... 

TimerGetFiles.Action()
  dim dlg As OpenFileDialog
  dlg = New OpenDialog
  gFile = dlg.ShowModal
  If f <> Nil Then
  // proceed normally
    gResult = 1
  Else
  // User Cancelled
    gResult = -1
  End If