|
I use the MethodInfo Invoke() Method. The Invoked Method is a drawing routine.
Is it right that the MethodInfo Invoke() Method is extremly slow?
|
|
|
|
|
Compared to a direct call, yes, it's very slow.
What are you trying to do, and can you do it with an interface? Making calls through interfaces is fast.
|
|
|
|
|
I thought I had an "extremly cunning plan" but hope you can tell me a better solution:
I'm programming a little game with a lot of UserControls. These UserControls are filled with Data. But I don't like to pass DataAccess references to all of these Controls, so I thought I do it like in C++. MFC C++ Prgs are splitted in UI Views and Documents. Each View can have a document. From this document it's very simple to update the views
(GetDocument().UpdateView(Name)) with new data.
In this scenario I wouldn't have to pass references to the DataSet; I just have to programm a document class which handles adding Document Items (Controls, which are "listening" to changes of the document) and the Controls Update Methods. I made it like this:
object array for the document items
String array for the Update Method Name of the Control
DocumentType, so I can Update only specific controls.
MyDocument.AddDocumentItem(this.AreaControl1, "AreaCtrlUpdate", DocumentTypes.AreaControl)
The Document has a DataSet and properties.
So when the documents data changed with the set method of a property this will Update my Document Items. To Invoke a Method of a object I needed MethodInfo.Invoke() Method. Each DocumentItem have to implement a method like CtrlUpdate(Document pDoc). I add as a passing parameter of the CtrlUpdate method the Document itsself.
What I found very good was first that Data is only stored at one place (in the document) and there is even no need to store IDs in the UserControls. Second there's no need to pass DataSet or DataAccess Object References because the DataSet is passed with the Document to the Controls Update Method. In the document I fix which Controls to Update if a property or the dataset changed. That's good because I can fix which Controls to update at only one place, in the document and there's no need that a control has object references to other controls which have to actualisize when the data was changed by the control. I just set the new property in the document and this will cause the Update Method of the other Controls.
I made a mistake and so I meant that MethodInfo.Invoke() is very slow (Seconds to Invoke).
So what do you mean with calling Methods through an interface? Is there a better solution for this scenario? Could you give me an example?
I think about to use databinding with these UserControls but I couldn't find examples how to set a datasource, datamember for a UserControl. Do you know how to set datasource of usercontrols?
Thank you!
Stefan
|
|
|
|
|
Here's what I suggest:
Define an interface:
interface IDocumentItem
{
void CtrlUpdate(Document pDoc);
}
and then implement it in each of the DocumentItem classes. Then, when you want to do the update, you can cast the DocumentItem to an IDocumentItem, and then call CtrlUpdate() through that reference. That will be fast fast.
Does that make sense?
|
|
|
|
|
This does really make sense! Yes that's what I searched. The problem was always that a casted object "looses" the classes methods...So now I see...
Thank you very much!
Stefan
|
|
|
|
|
STW wrote:
I use the MethodInfo Invoke() Method. The Invoked Method is a drawing routine.
Is it right that the MethodInfo Invoke() Method is extremly slow?
Someone once said that if you need to ask how big is the cost of Reflection, you can't afford it.
But there are much faster alternatives, like interfaces or delegates.
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
I explained my scenario to Eric Gunnerson. Hope you could help me to find a faster solution with interfaces.
Thank you!
Stefan
|
|
|
|
|
Can i access a function from a file which is not in an active project in a workspace????
Meaning, if i have 11 projects in a workspace and i want to access a function from a project that is currently not set as active one, can i do that?
|
|
|
|
|
If it is a DLL, yes, just add a reference in your current project. When the window pops up, select the .NET tab and "Browse" for the dll.
Rocky Moore <><
|
|
|
|
|
Hello,
I'm trying to bring to top an application. I followed several examples that I've founded but it doesn't work.
I have the instance of my application registered in the computer and I have access to it via Remoting. I've got a method (ShowMyWindow) that I want to call to show the main window of my application:
public void ShowMyWindow()
{
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, 3);
}
SetForegroundWindow(hWnd);
}
Now, for example, I've got a instance of my application running in my computer and I try to execute another one from the console. I obtain the already running instance and execute the ShowMyWindow method. The problem is that the result of this is I've got the console window on top and the icon of my application flashing in the task bar (I want to show it a the top of my screen!!!!! ) Instead, if my application is minimized, it works.... Any suggestion???
Thanks,
Iván Fernández
|
|
|
|
|
Did you try BringWindowToTop instead of SetForegroundWindow ?
"...hasn't really been well accepted ... as the ratings tell us so far " - Nishant S
|
|
|
|
|
Yes, I tried but it doesn't work anyway...
Iván Fernández
|
|
|
|
|
It's strange, because "The BringWindowToTop function brings the specified window to the top of the Z order"
"...hasn't really been well accepted ... as the ratings tell us so far " - Nishant S
|
|
|
|
|
Has anyone here used the Reflector program by Lutz Roeder? I just downloaded it yesterday and started toying around with it and found that it contains a decompiler. I wanted to know if it's actually that easy for a program written with .NET to be decompiler to it's original source. I tried it on one of my own programs and it outputs the code exactly as I typed it. I find that to be slightly disturbing.
- monrobot13
|
|
|
|
|
Well you kinda proved it to your self
This has been a big complaint about .NET in general. If you really want to make it harder for people to do this you can use some of the obfuscators out there. Alternatively, you could use MC++ to wrap native classes that you write.
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Since Java came in, we entered a new ERA, the Managed code ERA. At first it can look disturbing but at the end of the day you need to measure up what you can affort to be developing. I particularly like the way C++ still handling things, just look at Windows Forms and MFC, you can not compare them. MFC if far more stable ! However how long does it take to develop an application in MFC and another in .NET, furthermore how long would you take to work out portability of Unmanaged apps instead of Managed ones.
I have embraced .NET completely but i still want to keep C++ under the belt now, just like when I was embracing Java.
<Yoda>
The shroud of the managed code has fallen...Hmmm.hmm....
</Yoda>
Cheers,
ES
PS: Look into www.remotesoft.com, and have a look at their obfuscator and decompilers.
|
|
|
|
|
I still think Java out does c# however
|
|
|
|
|
|
Hi,
Can anyone please tell me a link to some kind of documentation on how to use the Regex class? How to make the pattern, group names and the other stuff?
Thanks
|
|
|
|
|
|
Thanks a lot. It was exactly what I needed
|
|
|
|
|
Hello, everyone.
Has anyone made an example of ListView so that user can drag item up or down in the list..
I want to make this function, however, the visual effect looks bad.
I hope when I drag an item, the item has a little effect (like window default drag effect), any body can help me? ...
Thank you !!
|
|
|
|
|
|
Hm... this a not bad example.
However, I hope to the effect of Drag&Drop is much clear.
is making own control the only way?
Any other good example the drag effect is much clear ?
Thanks.
|
|
|
|
|
How can I auto gen my code into code behind when I drag and drop myWebControl in to .aspx ?? show me the way how to do it
thanks!!!
Nho'c ti`
|
|
|
|