Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

At the moment I'm making an plugin manager application which dynamically imports UserControl(the look-a-likes of panels) dll files.
The main idea is that these plugins will be added each to a new tabpage in a tabcontrol.

Because I want to make sure that the manager will be running smoothly when one of the loaded plugins will be doing an infinite while loop for example.
When this occurs the entire form including all the plugins will be not responding... which is a bad thing.

So my idea was to run these plugins in a separate thread but since I couldn't find anything about it I had small hopes for my only tough:

Creating an instance of the usercontrol object inside a thread, and then add it to a tabpage in a thread safe way (doomed to fail):
// the void that will be executed as a thread
private void mrThread()
        {
            Template.plugin userControl11;
            userControl11 = new Template.plugin();
            userControl11.Location = new System.Drawing.Point(97, 57);
            userControl11.Name = "userControl11";
            userControl11.Size = new System.Drawing.Size(452, 393);
            userControl11.TabIndex = 0;
            AddControl(userControl11);
        }

        private void AddControl(Control usercontrol)
        {
            if (this.tabPage1.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(AddControl);
                this.Invoke(d, new object[] { usercontrol });
            }
            else
            {
                this.tabPage1.Controls.Add(usercontrol);
            }
        }


Adding the control works in the thread safe way, but unfortunately as I expected, the added control does not act like it's running in a thread.
Probably because it's overloaded?

Perhaps someone has an idea on how to accomplish this? or is it impossible for C#?
I want to make the project opensource (gnu gpl v3), so I won't be able to use propriety software.

Thanks!
Posted

1 solution

I definitely don't know of a direct way to do this.

If you haven't already, I would look at: Plug-in Manager[^]


AppDomain Isolation for Plugin / Run-Time Extensible Applications
[^]

And I would try to contact Jon Skeet (maybe through here: http://msmvps.com/blogs/jon_skeet/Default.aspx[^]). I say this based on a forum reply in which he said, "In my
case I was able to have a whole area of the main UI which the plugin
"owned", running that UI in a different thread."
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900