Invoking methods in assembly in dl causes main thread to wait?

  • Thread starter Thread starter Michel Schilthuizen
  • Start date Start date
M

Michel Schilthuizen

Hi,

I am working on an application that can use functionlity in some sort of
plugins. I have implemented this by using Assembly.LoadFrom and
MethodInfo.GetMethods.

The calling of the plugins is handled in threads.

All works fine, but when I call a method that processes for some time, the
mainthread (my form) becomes unresponsive.

I do not understand why and do not know how else to implement this. Does
anyone have suggestions?

Cheers,
Michel Schilthuizen

Code:

int ret;
Object medium;
MethodInfo mConfig;

----Initialisation of medium and mconfig was taken out, too much
code!! -----
ret = (int) mConfig.Invoke(medium, null);
 
Hi Michel,

Provided that your plug-ins do not interact with the main program UI in an
unpredicted manner, you should use BeginInvoke and EndInvoke to call
plug-ins' methods asynchronously.

There has been a serie of articles published on MSDN called "Safe, Simple
Multi-threading in Windows Forms" where different ways of running
time-consuming tasks in the backgroud were given.
 
Michel,

If you launch your plug-ins on another threads, you just don't need
BeginInvoke and EndInvoke as they simply run the passed delegate on a
separate thread taken from a dedicated thread pool. To be honest, I am out
of ideas what could lock up the GUI thread then.

I would suggest throughly checking the communication pattern between the GUI
thread and the other threads - for example, that no continuous polling exist
from the GUI thread.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

Michel Schilthuizen said:
Hi Dmitriy,

Thanks for your response. I understand the invoke functionality a lot better
now. However, BeginInvoke does not seem to be a member of the MethodInfo
object.

I don't think I properly explained what I am trying to do, so I'll quickly
try again and would appreciate it if you could let me know how (and if) your
solution could fit.

I have my main thread, which starts a 'core' thread. This 'core' completely
runs on its own, but will log to the main window in the future.

The 'core' thread reads plugin information from an ini file and starts
threads accordingly. These threads will use GetMethod and invoke, to call
methods in an assembly in a dll. The core will poll all plugin threads for
available information that needs to go to the other plugins. (Using a shared
object, with monitor to synch)

The plugin threads are used to poll the 'dll's' for information. These calls
may take a long time (web service calls, or a sleep in my test as I was
suspecting the web calls to be the cause). (In my test I only have one
plugin looking for information)

The mainthread is not doing anything at this time. When I want to select a
menu item, while one of the threads is making a call (using
MethodInfo.Invoke), the form just does not respond.

I will use your Begin and EndInvoke for the logging to the user interface,
but before I do that, I would like to solve this issue, because as far as I
am aware the action in the thread should not at all influence the
performance of the mainthread. (unless it is using a lot of CPU offcourse!)

I hope you can help me out again,
Michel

Dmitriy Lapshin said:
Hi Michel,

Provided that your plug-ins do not interact with the main program UI in an
unpredicted manner, you should use BeginInvoke and EndInvoke to call
plug-ins' methods asynchronously.

There has been a serie of articles published on MSDN called "Safe, Simple
Multi-threading in Windows Forms" where different ways of running
time-consuming tasks in the backgroud were given.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

Michel Schilthuizen said:
Hi,

I am working on an application that can use functionlity in some sort of
plugins. I have implemented this by using Assembly.LoadFrom and
MethodInfo.GetMethods.

The calling of the plugins is handled in threads.

All works fine, but when I call a method that processes for some time, the
mainthread (my form) becomes unresponsive.

I do not understand why and do not know how else to implement this. Does
anyone have suggestions?

Cheers,
Michel Schilthuizen

Code:

int ret;
Object medium;
MethodInfo mConfig;

----Initialisation of medium and mconfig was taken out, too much
code!! -----
ret = (int) mConfig.Invoke(medium, null);
 
Back
Top