What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Plugin lifecycle, coding practices

gajetto

New Member
Joined
Sep 9, 2014
Messages
4
Reaction score
0
Is there somewhere explained how exactly does the plugin lifecycle look like?

- How are static fields handled? (is assembly unloaded between plugin runs?)
- How are thread static fields handled? (is new thread created for each plugin run?)
- How are instance fields handled? (are new instances of plugin created on each run?)
- What is the preferred way to perform clean shutdown? So far I came with this (written from memory, might not be functional code)

PHP:
private volatile ManualResetEvent m_stopping;

public void PluginRun()
{
    try
    {
        // init

        while (m_stopping == null)
        {
            // plugin loop
        }

        m_stopping.Set();
    }
    catch (Exception ex)
    {
        if (m_stopping == null)
            m_stopping = new ManualResetEvent(true);
        else
            m_stopping.Set();
        throw;
    }
}

public void PluginStop()
{
    using (m_stopping = m_stopping ?? new ManualResetEvent(false))
    {
        m_stopping.WaitOne(TimeSpan.FromSeconds(30));
    }

    m_stopping = null;
    // more cleanup
}


How does archebuddy identify the correct assembly with plugin in plugins dir?


Should the "Core" class be used for all classes that need to call it's methods or it's just for the main "plugin" and I should pass reference / store it in static field to other classes that are not the main plugin? Why is this class not static? And just out of curiosity - what you guys have against c# naming conventions? It feels like you are trying to use c# for functional programming - woudln't f# be better for that? :p


Thanks :)
 
How are static fields handled? (is assembly unloaded between plugin runs?)
Yes, AB load each assembly in separate AppDomain. And unload this domain when you stop plugin
How are thread static fields handled? (is new thread created for each plugin run?)
Also yes. On plugin start AB Create new thread in new AppDomain, and call PluginRun in this thread.
How are instance fields handled? (are new instances of plugin created on each run?)
Also yes.
What is the preferred way to perform clean shutdown? So far I came with this (written from memory, might not be functional code)
All you need - control "Native\not managed" stuff and clean\dispose this stuff in PluginStop (like Window Forms\Threads).
Should the "Core" class be used for all classes that need to call it's methods
Yes. Core give you access to internal AB Core. Core instanse sends to your assembly before call PluginRun
 
Back
Top