|
Then apartently your not catching exceptions in the right place or aren't catching the right exceptions. I know you put Exception in your sample code in the root message of this thread, but I've seen many times where people don't sample their code accurately.
The other problem is that all the timers (and pretty much everything in System.Threading ) encapsulate native APIs. If a thread throws an exception in the native API, the timer thread will most likely quit. In your catch block, restart the timer by instantiating a new Timer , assigning it to the previous field (if any) and using the same TimerCallback delegate.
Also, you should consider using System.Timers.Timer instead, which has higher resolution and is pretty well guarded against exceptions (it still throws them, but typically recovers the timer thread).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, using System.Timers.Timer works.
modified 16-May-21 21:01pm.
|
|
|
|
|
I am trying to develop an custom listView that can be viewed in Windows XP and 2003 in GroupView ( Explorer-like ). This listView will have 2000+ items. The problem is that when it has 2000 items, it works very very slow. I've tried to set LVS_OWNERDATA and it increases the speed dramatically, BUT LVM_ENABLEGROUPVIEW is not supported with virtual listViews. The real question here is how you can make a listView very fast ( i mean not loading the items, fast when you browse through them ) , without setting LVS_OWNERDATA . My personal opinion is that this is a major bug in WindowsForms( the fact that it is so slow ) cause I tried the same thing in MFC and works fine. Please help me and possibly others who are dealing with this. Thanks in advance !
|
|
|
|
|
It's not a bug in Windows Forms (i.e., the .NET FCL) - it's just how the CLR passes messages around and encapsulates everything, since all those controls just encapsulate their Common Control equivalents. Even most of the painting is handled by the List-View common control itself. I'm assuming you're overriding WndProc in your derivative class (since that's about the only way to do it), so make sure you keep the code fast by using conditionals right away to determine if you even want to handle the message. If you still handle owner-drawing by creating Graphics objects, then you'll incur quite a performance penalty as managed objects are being created that encapsulate native handles. In this case, you'll probably be better off P/Invoking the GDI functions you need to do any painting.
Not that it really helps now, but the .NET Framework 2.0 will introduce both grouped views and virtual lists. I haven't tried grouping with thousands of items, but I'd assume its pretty fast since I know Microsoft is focusing on better performance in 2.0.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your reply. Even if I don't override WndProc at all and just create a listView with 2000 items, it's still slow when you're browsing the last items in the list. I've tried text and/or image callbacks but still doesn't help. Any ideea ? ( besides using a ListBox ) . By the way, when will .NET Framework 2.0 will be released ?
|
|
|
|
|
I'm sorry, but without seeing your code its hard to know what to suggest. Unfortunately, I really don't have the time (really).
The .NET Framework 2.0 is supposed to be out early in 2005 (haven't heard which quarter yet, though, despite my connections - because they don't know either). It's delayed primarily because of SQL Server 2005 (formerly code name "Yukon"). They want to release them at the same time since they're basically companion products.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi new to programming. I have a program that is supposed to compare two dates however when I run the program it reads the date as a string. What is the best way to compare a date to another date?
|
|
|
|
|
Use DateTime.Parse to parse a string into a DateTime (be sure to catch exceptions) and use DateTime.Equals or == to compare it to another DateTime . If you only want to account for the date portion of a DateTime , then compare one DateTime.Date to another. Same goes for DateTime.TimeOfDay (which is actually a TimeSpan structure). See the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
:-Dusing System;
namespace ConsoleApplication3
{
class Class1
{
static void Main()
{
//this is two date and the dateTime.Compare
//method will return 0 if both data are equal
//otherwise it will return 1
DateTime dt=new DateTime(2004,06,05);
DateTime dt1=new DateTime(2004,03,05);
int a=DateTime.Compare(dt,dt1);
Console.WriteLine(a.ToString());
//please don't use any other data type to reprasent datatime data types.
}
}
}
hai, feel free to contact
Sreejith SS Nair
sreejith@neosoft-tec.com
|
|
|
|
|
|
See the BitConverter class in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My class has a structure as such:
public class MyClass{
MyNestedClass Property1;
string Property2;
(... other members ...)
protected class MyNestedClass{
string PropertyA;
string PropertyB;
(... other members ...)
}
}
The reason behind encapsulating PropertyA and PropertyB is because I use the two properties more often than the other members in MyClass, even though PropertyA and PropertyB belong (describe) MyClass. That reason seems to be good when it comes to implementation.
However, somehow I don't think it is conceptually correct because I believe that a class should describe a complete entity.
I appreciate any comments.
|
|
|
|
|
Hi,
I am trying to create a login page.
Can someone point out to me how I may connect to a back-end Access database, and validate the entered username and password with the ones stored in the database?
Thanks for any help in advance
|
|
|
|
|
See my article, Role-based Security with Forms Authentication[^], for information on how to use a database to store and validate credentials using Forms Authentication, which provides many features over most home-brewed solutions (which are typically pretty insecure if you don't have a lot of experience with security).
The .NET Framework 2.0 will make this even easier with pluggable authentication back-ends to various front-ends (like Forms Authentication). For now, you're pretty much left with either extending what's available or implementing your own authentication modules.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Making my application i have suddently got and evil optimization question about "What are the internals of the array list" . Does any of you know if it is based on a linked list or on an array.
Also do you know where i can get my hand on a Simple Linked List or a Binary Tree.
Thank you for help.
|
|
|
|
|
An ArrayList is an array that grows dynamically by recreating the array (often doubling the size) everytime the bounds are surpassed.
As far as binary trees go, I suggest you take a peak at the MSDN article[^] regarding data structures. Part 3[^] of the article shows off some trees, including the source for a binary tree in C#.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
As Judah said, it uses a new array that typically doubles whenever the Capacity is reached.
To note, the ArrayList is used internally by many collections, so don't think you can escape it so easily!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank both of you.
I have another little question. What is the perforamce loss due to the type casting of array list elements. If my array list contains the same type elemets (or which share the same base class), could i use something equivalent to templates in C++.
Thank again.
Anton.
|
|
|
|
|
An ArrayList stores object s, so if you add reference types to the list, there's really no performance hit (1 to 2 extra instructions are required to cast, and optionally store, your type, but that's negligible). If you store value types, there is a slight performance hit because value types must be boxed and unboxed to store as an object . This is one of many reasons why generics will be great to have in the upcoming .NET Framework 2.0. Then you can declare a new list of value types, like List<int> ints = new List<int>(); .
This (un)boxing is typically not too big a problem if you don't use it a lot and don't need to milk your app for performance for every last drop. If you do, then you might consider implementing your own ArrayList -like class, implementing all the same interfaces (for the best support) and keep an array of whatever value type you need. Grow it when needs be, just like the ArrayList would.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In this case i will keep it, since making changes later would be much easier.
Thank you.
|
|
|
|
|
I have several images that have text on them, they are instructions that were turned into jpegs. Here is the question is there a way to de-construct the image so I can get just the text?
The reason for this insanity is reports. I have a report that "could" have lots of image data and as we all know there is no good way to split an image for a page break. Is there a good way to do this?
I will be coding for IE 6 only as this is an internal project, so x-browser solutions are not required .. but always welcome..
Any help on this would be great.
Thanks
William O'Malley
|
|
|
|
|
|
thank you for the article reference. very interesting stuff.
How ever I really don't have the money to spend on a third party add in. I was really hoping that I could find a way to do this with out using a third party add-in
thanks
William O'Malley
|
|
|
|
|
You don't need third-party software: the article describes how to create your own OCR scanning solution. However you implement, the concepts around OCR are your solution.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i use cards.dll to draw cards in my app.
and it works good in onpaint method
for example:
<br />
Graphics x = e.Graphics;<br />
<br />
hdc = x.GetHdc();<br />
x.ReleaseHdc(hdc);<br />
cardHandle.drawCardBack( hdc, 90, 10, eBACK.WEAVE1 );<br />
but if i try do the same thing offscreen, it does not work!
can someone explain why?
<br />
Bitmap offScreenBmp = new Bitmap(this.Width, this.Height); <br />
Graphics offScreenDC = Graphics.FromImage(offScreenBmp); <br />
<br />
hdc = offScreenDC.GetHdc();<br />
offScreenDC.ReleaseHdc(hdc);<br />
cardHandle.drawCardBack( hdc, 90, 10, eBACK.WEAVE1 );<br />
e.Graphics.DrawImage(offScreenBmp, 10, 10);<br />
I need it to rotate this card.
I have tried this method, but it does not worke.Graphics.RotateTransform(90f);
if u know another way how to rotate the card i draw with cards.dll, please tell me
thank u
|
|
|
|