|
To do that, you would need access to the delegate the Timer uses. In both Timer classes, System.Timers.Timer and System.Windows.Forms.Timer, this is marked as private. So in short, no.
Why would you need to know this?
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
well i have a timer that performs a calculation.... i can add as many events to it as i want (say i add five... Timer.Tick += ect) but i want to remove all the previous Tick Eventhandlers to ensure that i have no more then 5 attached to it. (the reason i want so many is that they will all be pointed to the same method, thus doing the calculation X times per cycle as aposed to one).
Any ideas / suggestions ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
While doing a stupid class project* I paid a visit to WindowsForms.net and ran across this little gem:
RegionMaster Controls[^]
I just glanced through the documentation and it looks pretty cool, though I haven't got a chance to dive into the source yet. Back to my proj. I've got less than two hours to include a bunch of garbage
*The project was actually ok until I read through the requirements and found I needed to include a sample of every little feature of powerpoint...
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Interesting...
Thanks for telling us about them.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
You don't do blogging do you James? That was circulating around the blogging world a couple of weeks ago.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
David Stone wrote:
You don't do blogging do you James?
Nope, I pretty much stick to CP; though I have started reading Chris Brumme's blog. Maybe one of these days I'll get into the whole blog thing
David Stone wrote:
That was circulating around the blogging world a couple of weeks ago.
Then why didn't you post it
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
James T. Johnson wrote:
Nope, I pretty much stick to CP; though I have started reading Chris Brumme's blog.
I was going to mention him to you...my head swims when I read that stuff.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
David Stone wrote:
my head swims when I read that stuff.
I can digest bits and pieces of it, I still don't get everything about his latest post.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
James T. Johnson wrote:
I needed to include a sample of every little feature of powerpoint...
Sometimes I'm still glad we are working on Linux
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
System.Net.IPEndPoint broadCastEndpoint=new IPEndPoint(System.Net.IPAddress.Broadcast,BGAME_PORT);
while(broadCastFlag)
{
try{
bsocket.SendTo(buffer,buffer.Length,SocketFlags.None,broadCastEndpoint);
Thread.Sleep(BGAME_INTERVAL);
}
catch(System.Net.Sockets.SocketException e)
{
System.Console.Out.WriteLine(e.ToString());
}
}
I just wanna broadcast a UDP packet to the LAN, as u see above. but when the code runs to 'Send to' method, an exception is throwed and tell me that 'attempt to access the socket in a unauthorized way'
Why?
Thanks.
|
|
|
|
|
Hey, I append text to a textbox in a c# web form, and i just want the scroll bar in the text box to automatically jump to the bottom so the user can see the new text. Similar to Windows Messenger which moves to the bottom as text is appended to the textbox from what u type in the send text box and send or what is received from your friend your chatting with.
Any suggestions??
I'm using myTextBox.Text += "\n\rHello There!";
Is it any different if i were to use myTextBox.AppendText( "\n\rHello There!" );
It states they are the same in the .net class library.
Can I set the position of the caret, so that i can call SetFocus() and then call ScrollToCaret()?? If this would work, how can i set the position of the caret??
|
|
|
|
|
Haven't dealt with it much in C#, but with all of the VB text boxes I've worked with, it works even without the ScrollToCaret() or SetFocus() thing.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Yeah, I never saw the method TextBox.AppendText() untill I was writing the first post, i was using the TextBox.Text += "", and the .Net Class Library says those 2 ways are the same. However, += does not advance the scroll bar, but AppendText() does. You must be using the method AppendText() then (but im not familiar with VB). Thanks for the reply though.
|
|
|
|
|
You do have to set the caret position, though.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
OK, I hvae a class Foo that holds a Brush.
Since Brush holds an unmanaged resource and implements IDisposable, I guess Foo has to implement IDisposable as well.
However, I'm still mixed up about Dispose, Finalize, and the recommended Dispose(bool disposing).
What's the "true" method to do here? Just
class Foo : IDisposable
{
protected Brush m_brush = null;
Dispose()
{
m_brush.Dispose();
m_brush=null;
};
} or is there more to it=
I know someday I'll get it
TIA
(Just today I found an article that explaiend it nicely - but it's poof! gone..)
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Ok, here's my understanding of it:
The Dispose method should be used to explicitly free up any internal resources, especially unmanaged ones such as handles etc. However, as far as I remember you should also call the Dispose method of an inherited class (if you have done so.
One other thing (although this is the big I'm shaky on -- haven't been doing this for a while now ), you may also be able to suppress any additional GC finalisation. To do this, the GC class has a SuppressFinalisation method or something. This is the bit I'd check up on in the docs, but as far as I know you seem fine.
However, I also think that its important for calling code to call your Dispose method. Of course, this then means making sure that should an exception be thrown, the Dispose method is still called. Consequently, you'll want to add a call to Dispose in the finally{} block.
In C#, you may also want to check out the using() keyword, but I don't use it that often, I find it easier to read if I explicitly call Dispose where necessary -- which kinda makes me think decent commenting/documenting is a good idea, which of course I abide by
--
Paul
"Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office."
- David Brent, from "The Office"
MS Messenger: paul@oobaloo.co.uk
|
|
|
|
|
peterchen wrote:
However, I'm still mixed up about Dispose, Finalize, and the recommended Dispose(bool disposing).
Finalize is the closest equivalent to C++ destructors that .NET has. The difference is that in .NET you can only clean up ValueType-based variables, in other words, IntPtr's that represent handles for P/Invoke use. This is because there is no guarantee on the order in which reference based (ie non-value types) will be Finalized.
That isn't very helpful in the long run, so the IDisposable interface came about so you could free up your managed resources. For example, flush a FileStream then close it. Because the FileStream uses a managed byte array to buffer the data you cannot use that byte array within the Finalize method. Sticky sticky.
Now to get to your question
When Finalize is called we know we can only deal with unmanaged resources, but when Dispose is called we can deal with both. Rather than have two places to dispose of unmanaged resources MS came up with another pattern to use, this time it is a protected method that takes a bool.
protected void Dispose(bool disposing)
Both Finalize and the public Dispose methods should call this method to do the dirty work work. The bool tells if you can dispose of managed resources (ie Dispose was called). If it is false then you should only get rid of unmanaged resources.
Now to tie it all together:
class MyClass : IDisposable
{
Brush myBrush;
IntPtr myHandle;
...
~MyClass
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void Dispose(bool disposing)
{
if( disposing )
{
if( myBrush != null )
myBrush.Dispose();
myBrush = null;
}
FreeSuppaHandle(myHandle);
}
} HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
How (or how much) does the .NET framework support editing the properties of a class?
I have a class which contains and manages a "color scheme" (i.e. mostly Colors and Fonts), and would like to allow the user editing it in a property list.
is there something already provided? Can I "plug in" the editing of a custom class? Or do I have to do it on my own?
TIA
Peter
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
peterchen wrote:
is there something already provided?
There is the Property Grid, which is the same control VS.NET uses. For some reason they don't have it show on the toolbox by default, just right click on it then choose Customize Toolbox then select the proprty grid.
Then you can drag and drop the control like any other.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks - found it!
Figuring out how to use is a nice task for tomorrow...
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
I have a strange question:
In .NET, is it still standard to prefix a class with "c" and an interface with "i" like has always been done with C++ and VB?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
No, and it was never standard to do that in any language that I can think of.
|
|
|
|
|
For instance, IPersist, IViewObject2, etc. and CCosmoDoc, CPages, etc. I know it is standard to prepend an "I" to the name of an interface. It was always standard in certain instances to pre-pend classes with a "C".
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
jdunlap wrote:
In .NET, is it still standard to prefix a class with "c" and an interface with "i"
Classes don't have a prefix, but the prefix on interfaces has stuck around. I presume to make them stand apart from other datatypes.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I already knew that I was still prefixed to interfaces, so I don't know why I lumped it in with the Class prefix thing. After reading the article mentioned below, I agree that prefixing classes with a "C" is futile.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|