|
I was wondering if it is considered bad style to make event handlers public. Say you do this:
public void Send(object sender, SomeEventArgs e)
{
}
I can't find anything in the coding guidelines that say one way or the other whether this is considered good or bad style. On the other hand, I'm having a hard time finding an example of public event handlers in the .NET framework.
The reason I would have for making event handlers public is that it would allow a third party to connect and disconnect event handlers in one object to events in another object. This would allow the flow of events through an application to be configurable during runtime.
|
|
|
|
|
It's not a real good idea unless you want code from outside your containing class to be able to call those handlers. Even code that isn't actually firing an "event" can call your handler if it uses the correct parameters.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: It's not a real good idea unless you want code from outside your containing class to be able to call those handlers. Even code that isn't actually firing an "event" can call your handler if it uses the correct parameters.
That's a good point to consider. If it's important that the event handler be called in response to an event, especially when the source of that event is important, it should probably remain private.
|
|
|
|
|
I have written a small application in Managed C++ that traverses the filesystem and comes up with an array of FileInfo objects representing each file within the path provided and its subdirectories. The point of this is to sort the entire list (potentially thousands of files) by size, filename and subsets, dates, etc. regardless of the directory they reside in. The problem I am having is that I can't sort the FileInfo type.
using ArrayList* files seems to be my best option for collecting the list,
then files->Add(someFileInfoObject) to populate the array.
This all works well and I get an accurate list of files. But files->Sort() needs to access IComparable::CompareTo, which is not implemented by the FileInfo class. I tried to create a new class, MyFileInfo based on FileInfo to implement IComparable, but was then told by Visual Studio that FileInfo is sealed, so I can't inherit from it.
I could spend my time creating custom sorting routines, but there's got to be a way to sort FileInfo objects that I'm overlooking. If I can't inherit from FileInfo, therefore can't add the IComparable interface to it, which seems the most elegant solution, I'm planning to create a __gc class MyFileInfo : public IComparable that contains its own FileInfo class rather than inheriting from it, then just passes along the information needed from within FileInfo. This seems it may work, but would require typing dozens of little stub routines just to allow MyFileInfo to pretend to be an extended FileInfo.
The reason I'm asking instead of just doing is that sorting files seems to be something that ought to be supported by default someplace. Any suggestions or ideas?
-mike
-www.channelmike.com
-- modified at 13:40 Friday 6th January, 2006
|
|
|
|
|
Sort is not something the FileInfo class really should support anyway.
How about using FileInfo to gather all the particulars for each file, like filename, parent folder, size, ..., and dumping that information into a ListView, DataTable, or even an Access database. You could then provide, or use as the case may be, the sorting methods without adding the overhead of the rest of the FileInfo class.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I think you can pass an IComparer to Sort(), just write your own FileInfoComparer.
|
|
|
|
|
Last time (1996) I developed with Delphi, there was a control with seperate "pages" to visually put controls onto and then switch the "pages" by code.
I.e. like a TabControl, but without displaying the tabs. Something like a "StackedPanelControl ".
Is anyone aware of such a control for Windows Forms 2.0?
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
|
I don't think there is a similar control. I would imagine that rolling your own control using Panels wouldn't be very difficult.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is the MarshallByRefObject class only used in Remoting or can it be used in the case of Windows Sockets too? Supposing, I want to serialize a class and send it over a UDP Socket connections to all the clients, then does the class have to be inherited from the ISerializable interface or the MarshallByRefObject class?
Can anyone help?
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Do you really think that sending a serialized class over UDP is a good idea? UDP does not garantee the arrival of packets, but more importantly, it doesn't garantee that they are received in the correct order!
Your deserialization code must be able to put up with this eventuality and be able to recover from it. What is the impact of not being able to recieve this object on your client, ... server? Can your data model withstand a few, some, or all or your clients not receiving this object?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
Thanks for your reply. Well my cirteria is that all the clients in the network have to broadcast a keep alive message so that the server can receive the packets. The packets will basically contain the Computer name of the client and the port number it is listening at.
Is UDP a good choice for this or is there any other better model for it?
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
The CLIENTS are broadcasting this information? This is a backwards idea that can be taken advantage of. The server can't broadcast a stream to different port numbers without broadcasting the same stream multiple times.
It should be that the SERVER broadcasts what its name is and any additional information the clients might need to connect to the server, such as a different port number. The clients can listen for that information being broadcast. If the clients do the broadcasting, suddenly your flooding the network with all kinds of broadcasts, instead of just one.
You CAN use UDP for this, but keep in mind what I said in my other post. UDP doesn't garantee delivery of anything! Can your data model withstand clients not receiving information with no ability to request a re-transmit.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
MarshalByRef is required only for remoting. For simple serialization to a file or a socket stream, implementing ISerializable (or using the [Serializable] attribute) should be fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote: MarshalByRef is required only for remoting.
Thanks for the info.
S. Senthil Kumar wrote: For simple serialization to a file or a socket stream, implementing ISerializable (or using the [Serializable] attribute) should be fine.
The class which is being serialized, should it be kept in a separate assembly, because when I kept the class being serialized in the same assembly which was broadcasting the meassage, it couldn't be deserialized in the receiving assembly. It gave a SerializationException saying that the "Client" Assembly does not exist.(Client being the name of my sending assembly).
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Hi,
I have recently intalled the Express Editions from Microsoft, and automatically installed Framework 2.0. What will happen if I install Visual Studio 2003 which comes with Framework 1.1? If I create a web project in Visual Web Developer, how will it know what Framework it will use? Won't there be any conflicts if various Frameworks are installed?
And if I compile a project, how does it know what framework to use?
Regards
ma se
|
|
|
|
|
iis configuration mmc plugin's virtual dir property page has a tab called asp.net that maps which runtime to work in. just Control panel-> administrative tools-> iis -> select virtual dir and right click ; in menu properties the tab with asp.net look at it....(it configures by web.config)
Mikail Çetinkaya . The C# DEveloper
|
|
|
|
|
Hi again.
When any other window gets on top of a pictureBox, that region of the pictureBox becomes shaded (doesn't refresh) when closing that window on top. I've tried to use the Update() method in the Paint event, but it doesn't work.
How can I do this?
Thanks.
|
|
|
|
|
How do I play two sound files at the same time without one cutting out?
I can not do that with PlaySound API.
Please help me.
|
|
|
|
|
Just a thought but can it be done with the PlaySound API running on separate threads?
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
I'm trying to get custom application icons but I can't seem to have a 16x16 AND a 32x32 application icon to load correctly. Basically I have a custom Application icon and a document icon. I am noticing the document icon is correct. Both on the application side and even in the Windows explorer side. Even when I change the Explorer view the icon changes size correctly. Now with the application icon, this isn't the case. This is the code I have in the resource file for my main window application.
IDR_MAINFRAMEGAMEMASTER ICON "res\\icon1.ico"
IDR_CGAMEONTYPE ICON "res\\calendar.ico"
IDR_MAINFRAME ICON "res\\CGameOn.ico"
icon1.ico is the 16x16 icon
calendar.ico is the document icon
CGameOn.ico is the 32x32 icon.
IDR_MAINFRAMEGAMEMASTER is the main frame I load when I set my configuration manager to "release". I also have a setting called "release -basic" in my configuration manager as well. I usually compile under the release therefore I am using the IDR_MAINFRAMEGAMEMASTER resource. The configuration above with the code I have will result in the application icon to be changed correctly as well as the explorer window to display the correct icon. But when I open the About box or change the explorer view to icons I get blanks. I'm not sure what is happening in why I get the document icon to work but not the application icon.
Any help would be appreciated.
Thanks!
|
|
|
|
|
Dear all,
In a C++ Windows Form application with several forms, and several generic C++ clases. I want to call the Main Form pointer or object form these other forms and classes, but do not know how...
As you can see, i'm very new to .NET!
Any help will be wellcomed, Thank you in advance!!
Eloy
|
|
|
|
|
Windows Forms does not use the MFC application model. I think you'd have to save your main Form somewhere. Alternatively you could enumerate Application.OpenForms, but again, figuring out the main form would involve traversing the parent-child hierarchy and all sorts of complexity. It'd be much easier to just save the main form in some static property that can be accessed throughout the app.
|
|
|
|
|
if your project or application is named "Foo" then the main form object is the Foo. Just add a static Foo^ class variable to your Foo class and initialize it in the constructor.
for example:
public ref class Foo: public System::Windows::Forms::Form
{
public:
static Foo^ myFoo;
Foo(void)
{
InitializeComponent();
myFoo = this;
...
}
...
};
Then, elsewhere in your code you can refer to your "main" form class as Foo::myFoo
hope this helps
|
|
|
|
|
Hi
Does any one know how to change the UserStrings Values in the .Net Metadata in code?
|
|
|
|
|
huh? explain what you're trying to do please.
|
|
|
|