NetLogic lifecycle

Learn how
FactoryTalk Optix
manages NetLogic threads, Start, Stop, ExportMethod execution, and task threading for reliable code. For code examples and advanced usage, see the FactoryTalk Optix NetLogic cheat sheet.

Execution contexts and threads

FactoryTalk Optix Runtime
includes two primary execution contexts: the UI thread and the behavior thread. The UI thread renders graphical objects and handles user input. The behavior thread calls
Start()
and
Stop()
methods on behaviors, including NetLogic, sequentially. These threads operate independently.
For more information about runtime pools, dedicated threads, and dispatch behavior, see Runtime threading model.

Start and Stop method lifecycle

The runtime calls the
Start()
method when a node (page, object, widget) activates. The runtime calls each
Start()
method sequentially, one at a time, on the behavior thread. Deeper nodes start before their parents. If multiple NetLogics share the same depth, their order follows tree traversal, but this is not deterministic.
The runtime calls the
Stop()
method in the exact reverse order of
Start()
, sequentially on the behavior thread. The runtime logs exceptions in
Stop()
and does not interrupt the sequence. After
Stop()
, the runtime disposes the NetLogic instance.
WARNING: Do not add or remove nodes from the page tree in the
Start()
method of a runtime NetLogic. If you need to modify the tree dynamically, change the page type definition and load the page on the session.
TIP: If a
Start()
method takes longer than 2000 ms, the runtime logs a warning. Slow
Start()
methods delay later NetLogic initialization and can cause visible freezes during page load. During page navigation, the runtime may call
Stop()
on the earlier page after calling
Start()
on the new page. If pages share global or external resources, this overlap can cause unexpected behavior.

ExportMethod execution and thread safety

Methods decorated with
[ExportMethod]
run synchronously on the thread that triggers them. The thread depends on the trigger source: UI thread, behavior thread, or a dedicated task thread. When an
[ExportMethod]
runs on a thread different from the one that owns a shared variable, concurrent access can occur. Use locks to protect shared data.

Task types and thread usage

FactoryTalk Optix
supports several task types for asynchronous operations:
  • LongRunningTask
    : Dedicated thread, thread-safe access to information model, use for long or blocking operations.
  • PeriodicTask
    : Dedicated thread, thread-safe access, use for recurring work.
  • DelayedTask
    : Dedicated thread, thread-safe access, use for one-shot deferred actions.
  • async/await
    (C#): Uses ThreadPool, not thread-safe for information model access, use for pure computation or I/O without node access.
TIP:
All
FactoryTalk Optix
task types are information-model safe. Use
async/await
or
Task.Run
only for operations that do not access project nodes.
For more information, see Run asynchronous code.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal