Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login
    The Maxon SDK Team is currently short staffed due to the winter holidays. No forum support is being provided between 15/12/2025 and 5/1/2026. For details see Maxon SDK 2025 Winter Holidays.

    background handler

    Scheduled Pinned Locked Moved SDK Help
    3 Posts 0 Posters 269 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 28/01/2005 at 11:17, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   8.5 
      Platform:   Windows  ; Mac  ;  Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      currently i'm having a lot of problems getting background handler to work.

      if possible it would be nice to see a very simple example showing where to allocate and deallocate in a normal plugin safely, and in general how to use this safely using these commands

      C4DOS->Ge.AddBackgroundHandler (when should this be called? at plugin registration? in a scenehook? in init? whenever the user presses my button?)
      C4DOS->Ge.RemoveBackgroundHandler (when and how should this be called safely?)
      C4DOS->Ge.StopBackgroundThreads (i presume whenever i want to call this?)
      C4DOS->Ge.CheckBackgroundThreadsRunning (i presume this is again similar to thread->IsRunning?)
      C4DOC->Ge.ProcessBackgroundThreads (this is the same as thread->Start correct?)

      what should be send through the void data handle?
      is it the same in addbackgroundhandler as in removebackgroundhandler?
      or is that a different peice of data? or a pointer to my background handler hook?

      thanks for any help given!

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 28/01/2005 at 11:47, xxxxxxxx wrote:

        You call AddBackgroundHandler() when you want to add a background handler. It can be called anywhere you want, though I'm not sure if you can call it from a thread.
        You call RemoveBackgroundHandler() to remove handlers. I think it can be called at the same places as above.
        You call Stop() to stop handlers of a given typeclass. Yes, call it whenever you want.
        Yes, I think so.
        No. This is called by CINEMA 4D when it is idle. It checks with the background handlers if they have something to do. Normally you don't need to call it yourself.
        Anything you want. It will be sent to your hook.
        Yes.
        No. No.
        The background handler cannot be a regular class function. Possibly it could be a static class function, if the compiler allows it. Here's a sample hook:

            
            
              Bool Handler_ActiveMaterial(void *data, LONG command, LONG flags)  
              {  
                switch (command)  
                {  
                case BACKGROUNDHANDLER_ISRUNNING:   
                  {  
                    return world->materialpreview && world->materialpreview->IsRunning();   
                  } break;  
                    
                case BACKGROUNDHANDLER_STOP:   
                  {  
                    if (flags&BACKGROUNDHANDLER_FLAGS_MATERIALPREVIEW)   
                    {  
                      if (world->materialpreview)   
                        world->materialpreview->End();   
                    }  
                  } break;  
                    
                case BACKGROUNDHANDLER_START:  
                  {  
                    return CheckActiveMaterialPreview(world->GetActiveDocument());   
                  } break;  
                }  
                return TRUE;  
              }
        
        Constant Description
        BACKGROUNDHANDLER_ISRUNNING
        

        |
        Return _<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#true1"_>_ color=#0000ff TRUE if the handler is currently running, otherw_<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#false0"_>_E0"> color=#0000ff FALSE.

        BACKGROUNDHANDLER_STOP
        

        |
        Stop the current activity._<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#true1"_>_#TRUE1"> color=#0000ff TRUE when the activity has stopped.

        BACKGROUNDHANDLER_START
        

        |
        Check if there's something to do. If _<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#false0"_>_tml#FALSE0"> color=#0000ff FALSE. In case there's something to do, directly start this_<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#true1"_>_s82.html#TRUE1"> color=#0000ff TRUE. There's also the possiblity to do a small job synch_<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#false0"_>_ants82.html#FALSE0"> color=#0000ff FALSE (pretend as if nothing was started).

        Note: As the background handler is processed in the main application thread this means that if you process something un-threaded the complete application will be blocked. E.g. some code that takes 10 seconds means that the user will not be able to click on any button or stop anything during that time. That's why only extremely short tasks must be directly processed, otherwise start an asynchronous thread.

        BACKGROUNDHANLDER_REMOVE
        

        |
        The handler i_<_a class=silent href= "mk:@msitstore:c:\program\cinema%204d\v8sdk\c4dr91sdkchm2005-01-25.chm::/pages/ge_math/enum_boolconstants82.html#true1"_>_Constants82.html#TRUE1"> color=#0000ff TRUE.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 29/01/2005 at 16:48, xxxxxxxx wrote:

          ah great! thanks a lot!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post