|
That depends on how expensive the instantiation is.
A few months ago I spent some time working on a technique to keep using one static StringBuilder throughout a library of static methods;
clearing it before each use rather than instantiating (and re-extending as necessary).
In the case of StringBuilder, my technique wasn't worth the trouble.
And for quick benchmarks like that I now use a System.Diagnostics.Stopwatch
|
|
|
|
|
When I open the network connection from the control panel, I can see several connecton for differnt network interface. example "Local Area connection";
I want to get this connection name == "Local Area connection" == programatically. For local machine it is possible using NetworkInterface Class but I am trying to get it for a remote machine.
NetworkInterface class can not used for remote machine. I used WMI for remote machine connection configuration but I am able to get all related information for any interface but no property is found in Win32_NetworkAdapterConfiguration class which is directly related to my requirement. Caption, Name, and other property gives me some other information but not the thing I am looking for.
Any idea, hint will be helpful.
Thank you
|
|
|
|
|
Cant you just do a file load and put the file of the Local Area Connection into your program, ive dont that for my internet debugger thing :P that might i work, i might be able to help you though.
|
|
|
|
|
Patrick_N3WB1E wrote: Cant you just do a file load and put the file of the Local Area Connection into your program,
Uhhh...would you care to explain what you mean by this?? A "file load" to get an adapter name??
|
|
|
|
|
s196675m wrote: I used WMI for remote machine connection configuration but I am able to get all related information for any interface but no property is found in Win32_NetworkAdapterConfiguration class which is directly related to my requirement.
Did you look at the WMI Win32_NetworkAdapter class??
|
|
|
|
|
|
Yes, I did and I have found the property. Unfortunately I overlooked this property in my previous investigation.
The Property name is "NetConnectionID" of "Win32_NetworkAdapter" class.
Thank you
|
|
|
|
|
Using VS2008:
I have the following code
public class MyEventArgs : EventArgs
{
public MyEventArgs()
{
}
}
public partial class BaseForm : Form
{
public delegate void MyEventHandler(object sender, MyEventArgs e);
public event MyEventHandler MyEventFunction;
public BaseForm()
{
InitializeComponent();
}
}
public partial class JohnsForm : BaseForm
{
private void button1_Click(object sender, EventArgs e)
{
MyEventFunction(this, new MyEventArgsArgs());
}
}
Intellisense is telling me this:
The event BaseForm.MyEventFunction can only appear on the left hand side of += or -=
If I move the event declaration info the JohnsForm class, Intellisense decides it's okay. Of course the workaround for this is to create a function in the BaseForm class that raises the event and call that function from my derived class, but why do I have to do that?
"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
|
|
|
|
|
Intellisense also states:
"(except when used from within the type 'yournamespace.BaseForm')"
Compiler Error CS0070[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, I didn't try compiling it because Intellisense insisted it was screwed up. I just want to why it doesn't treat it like a normal class member.
"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
|
|
|
|
|
John Simmons / outlaw programmer wrote: I just want to why it doesn't treat it like a normal class member.
By design, I suppose.
"...events are a special type of delegate that can only be invoked
from within the class that declared them. Derived classes cannot directly
invoke events that are declared within the base class"
How to: Raise Base Class Events in Derived Classes (C# Programming Guide)[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can't raise an event (directly) from a derived class. (WTF?)
Write a method to wrap it.
protected void RaiseMyEventFunction
(
blah blah
)
{
if ( MyEventFunction != null )
{
MyEventFunction(this, new MyEventArgsArgs());
}
}
And call that instead, it's good practice anyway.
|
|
|
|
|
PIEBALDconsult wrote: You can't raise an event (directly) from a derived class. (WTF?)
I already know that (now), and I mentioned writing a function to do it in the base class. I just want to know why I can't raise an event in a derived class, and perhaps where the reason is explained.
"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
|
|
|
|
|
Security, I guess, but I don't see it either.
|
|
|
|
|
I believe this is by design if you use the event keyword. I never use it, I just define a delegate and call it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
You cannot call directly events of a base class from a child class
You must declare a protected (or other scope) method on the base class to handle that
If you dont want that quit the "event" keyword
public class MyEventArgs : EventArgs
{
public MyEventArgs()
{
}
}
public partial class BaseForm : Form
{
public delegate void MyEventHandler(object sender, MyEventArgs e);
public event MyEventHandler MyEventFunction;
public BaseForm()
{
InitializeComponent();
}
protected virtual void OnMyEventFunction(object sender, MyEventArgs e){
MyEventFunction(sender, e);
}
}
public partial class JohnsForm : BaseForm
{
private void button1_Click(object sender, EventArgs e)
{
OnMyEventFunction(this, new MyEventArgsArgs());
}
}
Saludos!!
____Juan
|
|
|
|
|
It's designed that way, but I'm not sure why! Maybe they figured that people wouldn't be careful about null checking etc if they could just call an event directly but if they called the OnEvent it should be handled there? Just guessing!
I suppose the normal way (as you said) is the protected virtual void OnMyEvent(MyEventArgs e) method in the base and call that directly or override in the derived class.
Instead, you can mark the event as virtual in the base and override that in the derived class if you want.
BTW, it doesn't matter of course, but I normally use this if using my own event args, saves having to declare those delegates myself!:
public event EventHandler<MyEventArgs> MyEvent;
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: EventHandler<myeventargs>
Provided the event warrants an EventArgs; mine usually don't.
|
|
|
|
|
In that case
public event EventHandler MyEvent; takes care of it, and still no need to create a delegate ourselves, and just pass this, EventArgs.Empty when raising the event
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Not if I want to pass an int or something, my events tend to be very simple.
|
|
|
|
|
Cool - but doing it that way doesn't leave you any scope for expansion later on.
Some point down the road you may need to pass more than one piece of data. If that happens, you'll need to rewrite the delegate to take the new class/struct or additional parameters and every method signature invoked by it - that could be a whole lot of work! Using a custom event args avoids this so your apps won't break if requirements change.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'll burn that bridge after I've crossed it.
|
|
|
|
|
PIEBALDconsult wrote: I'll burn that bridge after I've crossed it
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello,
This is my first post to a site ever, please be patient with me. If I am not following a normal rule of conduct also please tell me.
My question/problem is:
I am trying to control the input to a form from another program. For example ( and this is just an example not being specific to my problem)
-- for example if you wanted a program to click -- using the mouse -- on the calculator that comes with windows 543 / 234 =
-- or you wished to enter "543" into the text field portion of the calculator.
The specific project is actually geared to control a piece of stock trading software automatically. But there is no COM or NET library to interface with.
I was wondering if this is even possible. Can you move a mouse and click on a form and not actually change focus... and enter data into a text box field when you have no clue about its handle or name.
-----
I am really looking for a starting point and feasability issues. If someone could point me in the right direction.
|
|
|
|
|
Yes, so long as it's not a WPF program, it's possible. Every control is a window, you can get the handle to a window and then send it messages. It's a lot of work tho, and it can be flaky, esp if the program changes.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|