473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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);
Nov 15 '05 #1
2 3205
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" <bu**@deputy.homeip.net> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
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);


Nov 15 '05 #2
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" <bu**@deputy.homeip.net> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
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 [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:#4*************@tk2msftngp13.phx.gbl...
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" <bu**@deputy.homeip.net> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
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);



Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Hamed Seifoddini | last post by:
Hi. This might be answered before, but I couldn't find it. How can you make the main thread to wait() This does NOT work : Thread.currentThread().wait(); Regards,
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
3
by: Nick | last post by:
My client uses a SQL Database to store their usernames and passwords, and I do not believe they have AD...no big deal... I wrote a class to create a generic identity and generic principal so that...
3
by: Daniel | last post by:
how do i access methods when the .net assembly was loaded with late biding? class Class1 { public static void Main() { System.Reflection.Assembly SampleAssembly; SampleAssembly =...
2
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
25
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid,...
6
by: Diego F. | last post by:
Hello. I'm using the socket class in an application and I use socket.receive to wait for data. The problem is that the interface gets locked while the receive method is executing. I want to see...
6
by: DaTurk | last post by:
I know in a WinForm you can check if an Invoke is inquired and invoke a method on the main thread. But can you do this in a class? Can I call Invoke(someMethod) in my asynch event handler? And...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.