|
I need to get the network drives so I have chased through from the CreateObject in VB to ManagementClass C#. I snaffled the following code from MSDN
using System;<br />
using System.Management;<br />
<br />
class Sample_ManagementClass<br />
{<br />
public static int Main(string[] args)<br />
{ <br />
ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");<br />
diskClass.Get();<br />
Console.WriteLine("Logical Disk class has " + diskClass.Properties.Count + " properties");<br />
return 0;<br />
}<br />
}
My problem is System.Management does not have a ManagementClass it only has Instrumentation.
I am using VS2008
Any ideas on how to reference to the ManagementClass
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I need to get the network drives
You need to query using ManagementObjectSearcher[^] class. This[^] shows an example.
Hope it helps
|
|
|
|
|
You need to add the REFERENCE for System.Management - Aaaahhhhh.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello everyone,
Sometimes I saw code which does not store reflection data structure MethodInfo, but stores MethodHandle each time and converts MethodHandle to MethodInfo (using GetMethodFromHandle) when MethodInfo is used to invoke the specific method using reflection.
My understanding is,
1. Using method handle could save memory;
2. But each time doing conversion from method handle to method info uses additional time.
So, it is a memory footprint/performance trade-off of choosing method info and method handle.
My questions is whether my above understanding of whether to use method handle or method info is correct. If not, what are the correct points?
thanks in advance,
George
|
|
|
|
|
Hello everyone,
There are two ways to use reflection to invoke a method,
1. Using InvokeMember;
2. Using GetType.GetMethod to retrieve a MethodInfo object, then use the MethodInfo object to invoke the method.
My point is from the result point of view, they are the same, but method 2 if more efficient if we want to invoke the method multiple of times by the same MethodInfo object -- since each time we call InvokeMember, it needs to find the method, nothing saved as MethodInfo object in method 2 and each time InvokeMember did the binding to find the same method.
My question is whether my point of understanding is correct and whether there any more differences/pros/cons compared with the 2 methods.
thanks in advance,
George
|
|
|
|
|
Sounds reasonable to me. I never use InvokeMember.
|
|
|
|
|
Thanks PIEBALDconsult,
regards,
George
|
|
|
|
|
George_George wrote: My question is whether my point of understanding is correct and whether there any more differences/pros/cons compared with the 2 methods.
Looks like your understanding are correct.
If you know the method signature at compile time, you can gain more performance by creating a delegate from the MethodInfo using Delegate.CreateDelegate(Type, MethodInfo)[^] and invoking that delegate.
|
|
|
|
|
Thanks N a v a n e e t h,
Looks like it could only deal with static method?
regards,
George
|
|
|
|
|
George_George wrote: Looks like it could only deal with static method?
MSDN
In the .NET Framework version 1.0 and 1.1, this method overload creates delegates for static methods only. In the .NET Framework version 2.0, this method overload also can create open instance method delegates; that is, delegates that explicitly supply the hidden first argument of instance methods. For a detailed explanation, see the more general CreateDelegate(Type, Object, MethodInfo) method overload, which allows you to create all combinations of open or closed delegates for instance or static methods, and optionally to specify a first argument.
See in the remarks
|
|
|
|
|
Thanks N a v a n e e t h,
1.
I am interested in the method of using CreateDelegate you mentioned here. But I am confused why it could improve performance, since you still need to create MethodInfo, and what are the differences internally compared with GetType.GetMethod.Invoke? Is it because GetType.GetMethod.Invoke binds at runtime but CreateDelegate binds at compile time, so CreateDelegate is faster?
2.
But if it is the compile time/runtime binds performance differences, my confusion is the reason of why using relfection is beause we do not know the type until runtime, does compiler time binding really practical even if it saves performance? Any comments?
regards,
George
|
|
|
|
|
1 - I do not know why it improves performance. I have used it and found the difference. Here[^] is a blog post which also explains it.
2 - There are situations where you know the signature of the method to invoke. The above given blog post explains how to handle when it is unknown.
|
|
|
|
|
Thanks N a v a n e e t h,
N a v a n e e t h wrote: There are situations where you know the signature of the method to invoke
From my study, I think not only signature but also the Type name is needed. Correct?
regards,
George
|
|
|
|
|
Hi N a v a n e e t h,
I read the article for quite some time, but confused about what means group method and extension method. I did some search and can not find any comprehensive materials covering this.
Do you have any referred documents for the 2 concepts?
regards,
George
|
|
|
|
|
I found out that the items under the menu strip can have a short cut key.. now i want a short cut key for my tool bars or some other components.. so what i did was to enable the key preview of the form then on the key down event, i tried to capture the keys.. but the problem is it only accepts one key at a time.. what if i press two keys like control + s or control + 0... how do i capture those combination?
|
|
|
|
|
When you check what key has been pressed, you can also check if any special keys are also pressed (like Ctrl, Shift) So to check for Ctrl+F:
void myEvent(object sender, EventArgs e)
{
if(e.Key == F && e.Ctrl)
{
}
}
Or err, something like that anyway.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hello everybody.
How can we change an image size ?
If there is an article about it please refer me to that.
Thanks in advance.
|
|
|
|
|
Mohammad Dayyan wrote: How can we change an image size ?
Resizing an image?
1 - Create a Bitmap with expected size
2 - Load image to a Graphics instance using Graphics.FromImage
3 - Use Graphics.DrawImage to draw that to the bitmap.
4 - Save the bitmap.
|
|
|
|
|
Ok, So I was obbing my program using 9Rays and whenever I enable String encryption the program messes up but when I do normal obbing with everything max it works. Also when I ob strings all the text in the program either has a [] in it or ends in a []. What is the problem? Hope I was clear.
Thanks,
Buckley.
|
|
|
|
|
IMO, ob used when we release assemblies. When you use debugger like VS or SD, your application will not work correctly. But if in release phase your application doesn't work, your ob application has to be changed
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
You were clear until you started abbreviating the word "obfuscate". Believe me - you have time to type the entire word.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello,
(I'm a newbie at C# but have programming experience)
I have a database with three tables. The model can be seen here: Data model[^]
I would like these tables to be populated in the DataGridView as can be seen here: DataGridView[^]
The start, end, ..text fields will be filled with entries from the table WBS.
The task combobox should have the WBS description selected
The project combobox should have the WBS's project name selected.
The project combobox should have been populated with all available projects in the project table and task combo box should have been populated with all available tasks for the chosen project.
How can I get this working (or at least guide me in the right direction)
Best Regards
Jocke
|
|
|
|
|
Hi,
Basic idea is that you create for example a datatable which is populated by using SELECT and it joins all three tables. This will get you rows to the grid (you can also use entity instead of a datatable).
The combo boxes are populated independently from the rows (they have a separate datasource), which means you use a separate datatable for each combo providing possible values. For the value to show you use DisplayMember and for the foreign key column, which defines selection, you use ValueMember.
Hope this helps,
Mika
|
|
|
|
|
Hello,
Im trying to make a little application to have a console application open and say 1 for addition 2 for multiplication, etc.
i do not know how to make a menu for a console where if i type 1 i need the console to read it and show the layout for the addition.
please help!
-Steven
krtek16@hotmail.com
p.s. i wrote it like this (addition example)
{
console.writeline("please enter first number to add");
string sNumber1Add;
sNumber1Add = console.readline();
double dNumber1;
dNumber1 = Convert.ToDouble(sNumber1Add);
console.writeline("please enter second number to add");
string sNumber2Add;
sNumber2Add = console.readline();
double dNumber2;
dNumber2 = Convert.ToDouble(sNumber2Add);
//add together
double dAnswerAdd;
dAnswerAdd = dNumber1Add + dNumber2Add;
console.writeline("The answer is + "
dAnswerAdd);
console.writeline("press enter to terminate");
console.read();
}
modified on Sunday, September 7, 2008 2:55 PM
|
|
|
|
|
if i don't misunderstanding about what you need, you have an application that call console application to execute something.
1. make console application with passing arguments (in main entry point "Main(string[] args)")
2. parse passed arguments in your console application to execute something.
3. use Process.Start to call your console application and specify arguments to pass.
otherwise if you do not need to create application caller please remove step no 3
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|