Thread Utility Manual

内容表

关于

The Cinema 4D classic API provides various functions to handle threads and thread related tasks.

警告
For MAXON API threading utilities see 线程手册 .

Utility Functions

Various tasks should only be performed from the main thread. For example any GUI interaction or any change of the currently active BaseDocument must only happen from the main thread. To make sure that such code is only executed in the main thread the following functions can be used:

  • GeIsMainThread() : Returns true if the code is running in the context of the main thread.
  • GeIsMainThreadAndNoDrawThread() : Returns true if the code is running in the context of the main thread and if the main thread does not execute any viewport drawing.
// This example shows how a context less function can check // if it is allowed to edit the active document.
static maxon::Result<void> SetActiveDocumentTime( const Float time) { // check if the function is called // from within the main thread if (! GeIsMainThreadAndNoDrawThread ()) { CriticalStop (); maxon::IllegalStateError( MAXON_SOURCE_LOCATION ); }
BaseDocument * const doc = GetActiveDocument (); if (doc == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); doc-> SetTime ( BaseTime (time)); EventAdd (); return maxon::OK ; }

Running Systems

注意
CheckIsRunning() does not check if the current code is running within the context of the checked task. See IdentifyThread() above.
// This example checks if the external render thread is running. // If so it should stop.

// check if the external renderer ("Picture Viewer") is running if ( CheckIsRunning ( CHECKISRUNNING::EXTERNALRENDERING )) { GeStopBackgroundThreads ( BACKGROUNDHANDLER_TYPECLASS_C4D , BACKGROUNDHANDLERFLAGS::RENDEREXTERNAL , nullptr ); }

Get Threads

These functions are used to obtain certain threads:

// This example will execute the while loop until the "Esc" key is pressed. BaseThread * const escThread = GeGetEscTestThread (); if (escThread == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// execute the loop until the escThread signals to stop while (!escThread-> TestBreak ()) { DoSomething(); }

延伸阅读

BaseThread::TestBreak
Bool TestBreak(void)
定义: c4d_thread.h:39
GetActiveDocument
BaseDocument * GetActiveDocument(void)
BaseTime
定义: c4d_basetime.h:24
BACKGROUNDHANDLERFLAGS::RENDEREXTERNAL
@ RENDEREXTERNAL
Render external.
Float
maxon::Float Float
定义: ge_sys_math.h:64
BaseDocument::SetTime
void SetTime(const BaseTime &t)
BaseThread
定义: c4d_thread.h:27
maxon::OK
return OK
定义: apibase.h:2532
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::Result< void >
CriticalStop
#define CriticalStop(...)
定义: debugdiagnostics.h:234
GeIsMainThreadAndNoDrawThread
Bool GeIsMainThreadAndNoDrawThread()
CHECKISRUNNING::EXTERNALRENDERING
@ EXTERNALRENDERING
External rendering.
GeStopBackgroundThreads
Bool GeStopBackgroundThreads(Int32 typeclass, BACKGROUNDHANDLERFLAGS flags, BaseThread *thread)
CheckIsRunning
Bool CheckIsRunning(CHECKISRUNNING type)
BACKGROUNDHANDLER_TYPECLASS_C4D
#define BACKGROUNDHANDLER_TYPECLASS_C4D
Cinema 4D background handler type class.
定义: ge_prepass.h:4605
EventAdd
void EventAdd(EVENT eventflag=EVENT::NONE)
GeGetEscTestThread
BaseThread * GeGetEscTestThread()
定义: c4d_thread.h:206
BaseDocument
定义: c4d_basedocument.h:490

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1