Plugin Architecture Question - Best Practice For Forms Update

C

cab0san

Plugin Architecture Question - Best Practice For Forms Update



I have an application that follows a simple plugin architecture. Yes,
it is my first plugin app, so please bear with me. There is an
interface defined, and followed by the host exe and plugin (or client)
dll. The plugins reach out into the world and get bits of information
(stock prices, new mail, disk space, rss feeds... whatever) these bits
of information end up as treenodes in a treeview in the host app.

My question is:

When a plugin is ready to deliver updated content, say perhaps by use
of a timer, what is the preferred way of notifying the host app?

(assuming that my plugin will be in a seperate thread)
Should I pass a reference to the form?
Do I raise an event?


I know that you should operate on winforms in the originating thread
only , so they don't play well with refreshes sent from timer threads
(or any other thread). I am able to use invoke to get around a few
things, but I was hoping to find a simpler solution, and wanted to hear
some opinions.
 
B

Bob Powell [MVP]

DLL's used by an EXE don't run on a separate thread. The DLL usually runs on
the EXE's thread. This means that your normal event handling systems work
just fine. Remember that things like TextBoxes and indeed the Form base
class are held in a DLL that's used by your EXE.

Timers such as System.Threading.Timer do indeed notify of timeouts on a
different thread. In cases where you use the more reliable timers you must
invoke correctly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
C

cab0san

Thank you for your reply.
Do you think it best to always use invoke since I cannot be sure which
thread a plugin will call a refresh from? Is there a way to synchronize
the calling thread with the winform's thread?
 
B

Bob Powell [MVP]

You can assume that if you're using System.Threading or System.Timers the
notification will arrive on another thread. Good practice however dictates
that you would chech the InvokeRequired property as a matter of course. If
at some later date you decide to use a windows forms timer or the user
creating the new plugin uses one the invoke will not be required.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top