-
-
Notifications
You must be signed in to change notification settings - Fork 107
Async and Thread Safety
SmartFormat makes heavy use of caching and object pooling for expensive operations, which both require static
containers.
SmartFormatter
s and Parser
s require one instance per thread.
When instantiating SmartFormatter
s from different threads, SmartSettings.IsThreadSafeMode=true
must be set (which is the default since v3.1.0), so that thread-safe containers are used. This brings an inherent performance penalty.
Note:
Static Smart
methods like Smart.Format(format, args) can be called in an async
/ multi-threaded context since v3.1.0.
The SmartFormatter
instance returned by Smart.Default
is flagged with the ThreadStatic
attribute. This means, that a new, isolated SmartFormatter
instance will be created for each thread. Any changes to this instance will only have effect within the thread (not for all threads).
When instantiating SmartFormatter
s from a single thread, SmartSettings.IsThreadSafeMode=false
should be set for avoiding the multithreading overhead and thus for best performance. The default, however, is SmartSettings.IsThreadSafeMode=true
- Syntax, Terminology
- Placeholders and Nesting
- string.Format Compatibility
- Character Literals in Format Strings
- HTML With CSS or JavaScript
- Data Source Extensions
- Default _ DefaultFormatter
- Lists _ ListFormatter
- Choose _ ChooseFormatter
- Condition _ ConditionalFormatter
- Null _ NullFormatter
- SubString _ SubStringFormatter
- RegEx _ IsMatchFormatter
- Pluralization _ PluralLocalizationFormatter
- Localization _ LocalizationFormatter
- Templates _ TemplateFormatter
- TimeSpan _ TimeFormatter
- XML _ XElementFormatter
- Extension Methods
- Home
- Common Pitfalls
- HTML with CSS or JavaScript
- Overview
- Main Features
- Formatters
- Extra Features
- Console and StringBuilder
- TemplateFormatter
- SmartSettings to control Smart.Format behavior
- Additional Info
- License