|
Your question is difficult to understand- are you asking how you should implement a timer that will show a message box?
Windows forms timer events are called on the UI thread via the message pump. The Threading timers are not.
|
|
|
|
|
They're all different... http://msdn.microsoft.com/en-us/magazine/cc164015.aspx[^]
System.Windows.Forms.Timer = Runs in your UI thread, and is part of the message loop. If your GUI is running slowly, this timer will become inaccurate. If you run a long loop on the GUI thread that blocks user input, it'll block this too. Not only will it be inaccurate, but if it falls behind, it will actually just skip any ticks it missed.
System.Timers.Timer = Runs in its own thread, and triggers events on a background thread. You can use its Synchronizing object to put its events on the GUI thread if you want, and that'll make it work basically just like the S.W.F.Timer, except that it won't skip ticks.
System.Threading.Timer = Similar to the System.Timers.Timer, but gives you finer control and is a little more complicated to use.
|
|
|
|
|
The System.Windows.Forms.Timer control does not use a seperate thread to raise it's events. It's always going to use the application message pump to raise the event on the UI thread. Since it's using the message pump, the time that you actually see the event fired won't be entirely accurate.
The other timers use a seperate thread to call back your code, though the implementations of what you get back and how the timers behave vary slightly.
|
|
|
|
|
|
hmm... the timer event is triggered with the interval you specified. So as long as you don't disable it after the first event it will keep on executing the code. got nothing to do with threads
|
|
|
|
|
I want make Button in c# windowsForms export DataGridView Table to dbase IV.
How can i doo that?
Someone can help me plz ?
|
|
|
|
|
Hi,
I write some application that need to get new bitmap every 50 millisecond and store it on some bitmap collection.
When the size of the bitmap collection is 300 - the application remove all the bitmap and will collect the new bitmap again.
I see that on this case the GC will run more often - and i want to make somehow less running of the GC.
How can i do it ?
Thanks.
|
|
|
|
|
Advice I see very often is to let GC do it's job as it wants, because you're not smarter than it is.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Yanshof wrote: store it on some bitmap collection
So long as it's referenced (stored) somewhere it will not be eligible for collection.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
There is only one good way to reduce the GC activity, and that is by reducing the need for memory due to the creation of new objects all the time. So get a smarter approach to whatever it is you want to achieve, or reduce the size of your objects, or reduce your need for objects, or recycle them. Recycling is a very effective means, but it isn't always easy as it works best for lots of objects of the same size; it also puts lifecycle management in your hands (as it was before GC-based languages got popular).
If you are creating synthetic bitmaps, recycling could be rather easy; if OTOH you load the bitmaps with existing (e.g. Bitmap.FromFile) it may not be practical.
|
|
|
|
|
Use unsafe code and allocate the space ahead of time for your bitmap collection. Don't use native objects.
|
|
|
|
|
Don't program in .Net.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
1. Just don't care.
2. Create a pool of recyclable bitmaps and manage them on your own.
3. Re-think your design
Remark: GC does the job it was designed for - it recognizes that your collection is not referenced by the program so it is collected. One point I don't understand is this: The collection you are talking about must be a temporary, otherwise it would not be gcollected. In that case, what other behaviour would you expect?
|
|
|
|
|
If i call 'dispose' at the end of use of each bitmap - I releasing the memory and i slow down the GC call - right ?
|
|
|
|
|
No, on the contrary, at least if we are talking about System.Drawing.Bitmap. This one implements IDisposable and allows you to explicitely release the resources and to notify the GC that there is no need to finalize this object.
It depends a lot on the scenario in which you are using it:
If you create a Bitmap and use it in a local scope, use the using syntax:
using (Bitmap tB = new Bitmap(...)) {
}
If you need to keep references to Bitmap object (as you apparently do), then take care that after calling Bitmap.Dispose no reference to that object exists in your program. Assuming your Bitmap container is a Queue<Bitmap> :
using (Bitmap tB = BitmapQueue.Dequeue());
|
|
|
|
|
How can I check file is broken?
I want to get alarm when text file or .sdf (database file) file is broken in specified directory.
How can I check it in C#?
Thanks...
|
|
|
|
|
What do you mean by broken?
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
|
You'd need to have something to compare it to; the original, undamaged file then carry out a byte-by-byte comparison. You could create a checksum of the original file and store that then compare that to the checksum of the damaged file. You could also compare file lengths; if they are different then so are the files (obviously). If you don't have the original file to compare to then you might be a bit stuck unless the damage you are looking for is quite specific and testable.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
digital man wrote: If you don't have the original file to compare to then you might be a bit stuck unless the damage you are looking for is quite specific and testable.
That's testing whether the .sdf has changed, compared to the original. It's probably a SqlCE database, and it's checksum would change on every update/delete.
I are Troll
|
|
|
|
|
dataminers wrote: How can I check file is broken?
Define "broken"; a textfile may contain any character, printable or not. Does the textfile have a specific format that you can compare against?
The SqlCe database is somewhat easier to verify, and that's documented over here[^]
I are Troll
|
|
|
|
|
I have print statement in Sql Sp. How can I bind print statement to DropdownList
|
|
|
|
|
hi friends & all seniors,
i have created a user control. i want to add it dynamically to list view. for certain criteria i am saying
for(certain condition)
listview.control.add(object_of_createdUserControl);
If i am using this for flow layout panel it works fine. but this fails for list view.
i dont get any error and all the objects of user control are added to the listview but only the first is displayed.
hope i have stated my problem correctly
Looking forward for your kind response!!
Regards
Samir
|
|
|
|
|
Did you check the Location property of your newly added user controls? Perhaps they are all at the same place, and hence only one of them appears on the screen.
|
|
|
|
|
In general if you want to add multiple controls to a Listview then you need to produce a custom list view control derived from ListView.
Check out this link C# Listview 1.3
|
|
|
|