Page 1 of 1

App go to sleep

Posted: Mon Aug 27, 2018 9:42 pm
by mk-soft
Hello,

I have a server running as an app.
If the app is minimized, the thread with the server reacts very slowly after a short time. It can take up to 8 seconds until the sent packet arrives at the server.
How to prevent the app from going to sleep.

Link to server and client: viewtopic.php?f=12&t=66075

Re: App go to sleep

Posted: Tue Aug 28, 2018 6:12 am
by wilbert
There are serval threads about App Nap.
Maybe the info in those threads can help you :?

Re: App go to sleep

Posted: Tue Aug 28, 2018 12:51 pm
by mk-soft
Thanks wilbert,

this code from Daniel is help...

Code: Select all

  ; -----------------------------------------------------------------------------------
  
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    
    ; Author : Danilo
    ; Date   : 25.03.2014
    ; Link   : https://www.purebasic.fr/english/viewtopic.php?f=19&t=58828
    ; Info   : NSActivityOptions is a 64bit typedef - use it with quads (.q) !!!
    
    #NSActivityIdleDisplaySleepDisabled             = 1 << 40
    #NSActivityIdleSystemSleepDisabled              = 1 << 20
    #NSActivitySuddenTerminationDisabled            = (1 << 14)
    #NSActivityAutomaticTerminationDisabled         = (1 << 15)
    #NSActivityUserInitiated                        = ($00FFFFFF | #NSActivityIdleSystemSleepDisabled)
    #NSActivityUserInitiatedAllowingIdleSystemSleep = (#NSActivityUserInitiated & ~#NSActivityIdleSystemSleepDisabled)
    #NSActivityBackground                           = $000000FF
    #NSActivityLatencyCritical                      = $FF00000000
    
    Procedure BeginWork(Option.q, Reason.s= "MyReason")
      Protected NSProcessInfo = CocoaMessage(0,0,"NSProcessInfo processInfo")
      If NSProcessInfo
        ProcedureReturn CocoaMessage(0, NSProcessInfo, "beginActivityWithOptions:@", @Option, "reason:$", @Reason)
      EndIf
    EndProcedure
    
    Procedure EndWork(activity)
      Protected NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
      If NSProcessInfo
        CocoaMessage(0, NSProcessInfo, "endActivity:", activity)
      EndIf
    EndProcedure
    
  CompilerEndIf
  
  ; -----------------------------------------------------------------------------------
Is calling inside of threads!