User interface not updates when call CURLSMBS in a Module Method


Across the years I’ve collected thousands of links in a text file, and it’s time to move them to a link manager, so I’ve wrote an small program that process that txt and creates a valid html bookmark file.

I’ve been tagging and commenting “someway” the links in that file when added them, so I’ve get some reasonable bookmarks file.

As an improvement, I want to add every link site and added a module method that I pass the URL, and gets the title, it also works

My problem is that I’ve a listbox where I shown the progress (and a textfield as a counter) but when call the method that gets the title, it not updates until finished.

There is no timer, I push a button, call a method (again a module method) that open, scans and writes the output (also updates the listbox and counter) and works well. But if I insert the call to the method that gets de then even works, the UI is not updated.

I’ve tried Window.Refresh, ListBox.Refresh but no luck.

I’ve also created a class with a method for this instead de module’s method, but the result is the same.

Can anyone tell me why and how to solve it?


How do you use CURLSMBS?

do you run it on main thread with Perform?
Set Yield = true?

Or run on a thread?
Maybe with PerformMT to move work to a preemptive thread?

Or use CURLSMultiMBS class to run it asynchronously?

Hello Christian, is a “quick and dirty” solution, no threads, is a method that I call from the loop that reads the file read/write. Also tested with PerformMT but the same. Will try CURLSMultiMBS, ran the example but wrote here before trying any more, as i don’t understand why :slight_smile:

This is the code:

From the loop I do (results is a dictionary that has 2 keys: url and comment that I extract from my lines with a RegEx):
Upper part of loop

Dim title As String = getTitle(results.Value("url").StringValue)

outputStream.WriteLine("<DT><A HREF=""" + results.Value("url").StringValue + """ ADD_DATE=""1697629501"" PRIVATE=""1"""  _
+ " TOREAD=""0"" TAGS=""test"">" + title + "</A>")

The loop continues

And getTitle method (in module, receives url As String, returns String):

Dim curl As New CURLSMBS

curl.OptionURL = url

Dim result As Integer = curl.Perform
If result <> 0 Then
  return ""
End If

Dim data As MemoryBlock = curl.OutputData

Dim html As String = data.StringValue(0, data.Size)

// Los datos del MemoryBlock data están sin codificación. Ponemos UTF8
html = html.DefineEncoding(Encodings.UTF8)

Dim parts() As String = html.Split("<title>")

If UBound(parts) > 0 Then
  Dim titleParts() As String = parts(1).Split("</title>")
  If UBound(titleParts) > 0 Then
    Dim title As String = titleParts(0).Trim
    // Por algún motivo hay que volver a poner la codificación a title (no parece "heredarla") tras el Split
    title = title.DefineEncoding(Encodings.UTF8)
    return title
  End If
End If


First thing would be to set “curl.YieldTime = true” to true.
That allows other threads to work better.

But you may want to put the whole work on a Xojo thread to do it.
Then you could even use PerformMT to make it more smooth.

Or you adapt CURLSMultiMBS class to do it: Easier multi transfer for our Xojo CURL Plugin

Thanks again YieldTime=true done nothing.

I’ll try the thread thing, but as it’s a run once and no again program don’t want to waste much time with it.

Once the links exported, will work with the manager only.

Thanks again

CURLSmultiMBS is super-easy to use now, with the new SharedInstance and delegate features. You just load up a CURL and add it to the shared instance with a delegate telling it where to go when it’s done. Don’t use SharedInstance in an app with non-shared instances, though, as that will unfortunately result in runtime errors.

I’d love to hear details on this.

Thanks Julia, finally I did inside a Thread with “Classic” CURLSMBS.

Hello Christian, at the end I move all processing code (with CURLSMBS) and update the UI via AddUserInterfaceUpdate Event.

All working well.

I really don’t know how to manage this with CURLSMultiMBS as I must get every title when processing a line from origin links file.

Thanks by the support.

So far unable to reproduce. I made a test project and the SharedInstance and an embedded instance seem to coexist ok. I do notice that the TransfersFinished event of the embedded instance fires when the shared instance completes its last transfer - not sure if that’s expected or not.

In my big app I think the exception was thrown when an embedded instance fired TransferFinished, but it was a month or so ago and the details are already fading, sorry. Getting rid of the embedded instance and using only the shared instance solved that problem.