#Pragma DisableBackgroundTasks true

Qualcuno sa spiegarmi a cosa serve questa istruzione?

#Pragma DisableBackgroundTasks true

anzi, in generale, l’uso di questi “Pragma” non mi è affatto chiaro. Qualcuno sa spiegare in breve? o linkare qualcosa…

Used to disable calls to the framework inside of loop iterations to see if it needs to switch threads or perform other tasks (such as polling the debugger socket in a debug build). It is specific to the scope the pragma is in and does not affect other methods you may call from your method. It also does not disable preemptive thread switching in the OS itself. Using this pragma can speed up very processor-intensive operations. Do not use DisableBackgroundTasks within web applications as it will prevent other sessions from running until the background tasks are resumed. This could cause sessions to disconnect or other undesired behavior.


I had already read that page which, unfortunately, tells me very little :frowning:

thank you all the same

It basically means that the only thing running in that thread will be your code until it completes or you yield.

Xojo can automatically yield (do other things) on loop boundaries if it needs to, this will stop that happening.

Basically I’m using CurlsMultiMBS (TransferFinished event), with the following code (copied from an example of the Plugin, but without really understanding what this first directive does). Since I have some operating problems, I thought that my problem might be there (maybe change true to false? But I’m saying it like this, at random, without understanding the real meaning of the directive)

#Pragma DisableBackgroundTasks true

  if result <> 0 then
    dim d as string = curl.DebugData
    dim f as FolderItem = App.rifPercorsi.CartellaLog.Child("curl.log")
    dim t as TextOutputStream = TextOutputStream.Append(f)
    d = ReplaceLineEndings(d, EndOfLine)
    dim arrivato as String = curl.FormData
    dim inizio as Integer = arrivato.InStr(">>>") + 2
    dim fine as Integer = arrivato.InStr("<<<") - 1
    dim strIdEmail as String = arrivato.Mid(inizio, fine-inizio+1)
    strIdEmail = strIdEmail.Replace("<", "")
    strIdEmail = strIdEmail.Replace(">", "")
  end if
Catch eccez as RuntimeException
  App.logger.Logga("errore in CURLSMulti.TransferFinished", True)
end try

I’ve not used CurlsMultiMBS so I don’t know if it will trigger while another even is running. The way to check if this is being called mid process is put a system.debuglog(“start”) and system.debuglod(“end”) at the start and end, if you have debug output where there are two starts next to each other then you know that two of these are running at the same time which might be the issue you’re trying to detect.

What problems do you have with CurlsMultiMBS? Using DisableBackgroundTasks is always dicey because users shoot your app down when they see the beachball. I’m using CurlsMultiMBS, too, and don’t use DisableBackgroundTasks.

This function does not contain any loops, so it should have no effect using DisableBackgroundTasks there.

“users shoot your app down when they see the beachball”??? :exploding_head: I can’t translate this… what it means? :-/

The “beachball” is the spinning wheel that appears when the app is unresponsive. Users interpret that as a crash. In reality, the app is working, but too busy to update the UI. It’s not a good look. :slight_smile:


damned slang! :slight_smile:

thanks anyway.

My problems do not concern the gui, but the fact that, in certain cases, at some point the messages stop starting. I believe the problem is due to the mail account and its limits. I was still investigating, looking for errors in my software module

Hehehe… I’ve been immersed in Murican culture for 18 years when working at Opel/GM.

There is a setting for Gmail to limit downloading of emails. See Why does Gmail only archive the latest 2000 emails?. Some account have a “Fetch rate limit”.

I tested the solution also with different email provider.

Please show your code or make an example. Everything else should download fine. I only use CURL for downloading external files for emails. For emails themselves I found CURL too simple for my needs.

I use CURL only to send email. I have not to read them.

what are the alternatives to CURL?

My code is hardly reportable. Different functions distributed on different levels.
In summary: the program generates documents that must be sent as attachments. The messages are first recorded on the database. A timer calls up a procedure that creates the emails and passes them to CURLSMulti, which provides for the actual sending. At TransferFinished the messages are deleted from the database. All this happens in the background, while the user continues to do other things with the program.

The joys of finding bugs in complex code…

Can you describe in more detail what problems you have? Sending emails isn’t that complicated. You should just be aware that there usually is a send limit on IMAP accounts to prevent spammers.

Can you make an example that uses a fixed number of emails and a fixed text with CURL?

  if m = nil then
    // first
    m = new CURLSMulti
    t = new CURLTimer(m)
    gest = gestore 
  end if
  dim keys(), k, v as variant
  keys = gest.dizMsg.keys()
  for each k in keys
    if gest.dizMsg.HasKey(k) then
      dim cmsg as CURLSMBS = gest.dizMsg.Value(k)
      if cmsg <> Nil then
        App.logger.Logga("[EMAIL_SENDER]: aggiunto a CURLSMulti il msg con Id " + k)
        if m.AddCURL(cmsg) then
          // ok
          gest.dizMsg.Value(k) = Nil  'così l'id rimane memorizzato e non viene reinserito, ma non verrà nuovamente passato al CURLSMulti con metodo AddCurl
        end if
      end if
    end if
Catch eccez as RuntimeException
  App.logger.Logga("errore in CURLSMulti.Work", True)
end try

Shared Method “Work” of class CURLSMulti (CURLSMultiMBS)

You should just be aware that there usually is a send limit on IMAP accounts to prevent spammers.

Yes, I think that was the problem. Using a not free account, it work better.

There are so many rules in the servers… daily limit, limit in small unit of time (for example 5 minutes), ecc ecc


Except for single emails you had better use something like SendGrid or Amazon SES.

thanks for the directions. I’ll take a look. Although, at first glance, they seem a bit difficult to use