|
Have you checked the innerException of the Exception('Exception has been thrown by the target of an invocation') ??? whats it saying ???
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
More info is required because there are many reasons this exception can be thrown. Is it a stored procedure that you are calling? Does it always work the first time? Stuff like that
Architecture is extensible, code is minimal.
|
|
|
|
|
Provide some code.........
|
|
|
|
|
Before executing the query, try checking that the .Count of said query is positive.
This might solve your problem.
|
|
|
|
|
Sorry about the delay in getting back to you all - have been out of the office and based in Australia.
Code that executes with the query is as follows:
try
{
this.file_InfoTableAdapter.fFile_File_Open(this.salesDataSet.File_Info, ((int)(System.Convert.ChangeType(fFile_Open_File_Text_Box.Text, typeof(int)))));
this.saleInformationDataGridView.Sort(this.saleInformationDataGridView.Columns["dataGridViewTextBoxColumn9"], ListSortDirection.Descending);
photoListBox.Items.Clear();
photoListBox.Items.Add(file_NameTextBox.Text + "_a.jpg");
photoListBox.Items.Add(file_NameTextBox.Text + "_b.jpg");
photoListBox.Items.Add(file_NameTextBox.Text + "_c.jpg");
photoListBox.Items.Add(file_NameTextBox.Text + "_d.jpg");
string photoDisplay = "P:\\" + localityTextBox.Text + "\\" + file_NameTextBox.Text + "_a.jpg";
this.photoBox.ImageLocation = photoDisplay;
land_use_codeTextBox.ReadOnly = true;
land_areaTextBox.ReadOnly = true;
construction_yearTextBox.ReadOnly = true;
room_countTextBox.ReadOnly = true;
wall_construction_codeTextBox.ReadOnly = true;
roof_construction_codeTextBox.ReadOnly = true;
building_areaTextBox.ReadOnly = true;
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
I have limited knowledge about avoiding exceptions, but it is my understanding that all the code underneath the running of the query is being run even if the query returns no result? Leading to the exception?
But to be honest, I really have no idea... I do know that there is a lot I could improve in the code, but it is a very much "Learn as I go" approach... Which of course isn't the best, but I can only learn and get better!
Joe
|
|
|
|
|
Joe follow Paw Jershauge's advice.. look at the inner exception
|
|
|
|
|
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application.
Is there any other approaches to add them to list view without application freeze?
Чесноков
|
|
|
|
|
|
That does not solve application freeze. You can not move the window
Чесноков
|
|
|
|
|
First, putting 100,000 items in a ListView control is ridiculous. Do you really think a user wants to scroll through all that just to find a particular record??
If you add all the items to the listView all at once, there's no way to avoid the "freeze". That's because the UI thread has to handle adding those items to the ListView. it cannot be done from another thread because you can only maniplute a control on the thread that created it.
You can, however, add each item tot he ListView, one a few at time, from a background thread, by Invoking a method on the UI thread to add just a few items at a time. This will give the UI thread time to handle other requests, but it'll take considerably longer to add your 100,000 items.
You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
|
|
|
|
|
Dave Kreskowiak wrote: You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
Have you ever ran Windows Events on your machine?
How many events are there in a list view for a couple of years e.g. windows applications
It does not freeze as you run it either.
Чесноков
|
|
|
|
|
See my answer below.
I must get a clever new signature for 2011.
|
|
|
|
|
Chesnokov Yuriy wrote: Have you ever ran Windows Events on your machine?
What Dave was saying is not that can't be done, or even that it is particularly difficult.
What he was saying - and I agree wholeheartedly - is that if you are loading 100,000 items into a listview, then your design is seriously flawed. It doesn't matter if other software does it: it is still a stupid idea and evidence that the designer / programmer is lazy.
Think about it from the point of view of the user. How do you find what you want in a list of 100,000 items? If you got 50 to a page, that is 2,000 pages to scroll through. Instead, give them searches, give them filters, show the top twenty and tell them how many more there are. Does Google load all 10,000 hits into a single page? I wonder why not!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: How do you find what you want in a list of 100,000 items
There is scroll bar, I can scroll them all easily and find event I'm looking for.
Filtering is another extension to consider, the problem is to load them all at once.
Why Microsoft can do that and we can't?
Was it the serious desing flaw in windows event viewer or not we may further argue.
OriginalGriff wrote: Does Google load all 10,000 hits into a single page
Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem.
If it hangs IE to load some of the pages with java which fits into a single window, consider what would happen with a page consisted of 10000 links.
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: There is scroll bar, I can scroll them all easily
Try scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".
Chesnokov Yuriy wrote: Why Microsoft can do that and we can't?
You're referring to the Spy-program, where a ListBox is used for logging. Microsoft is using the same technique in it's Sql Profiler. The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.
Now, adding text to a collection that's displayed in a control doesn't take much time. Loading a lot of records from your database and adding them to your list will take a lot of time, especially if Windows keeps repainting after each fresh insert.
Chesnokov Yuriy wrote: Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem.
That's far-fetched, your computer won't run out of memory if Google replies with more than 50 results. It would be rediculous to assume that you're going to read over 500 results, so they send you what you're probably going to use. How often did you navigate to the second result-page?
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: ry scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".
honestly, you have to scroll to specific time, and event icons are pretty distinct, and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events. while scrolling time column is pretty visible as you scroll it.
I'm off alcohol that enables me to scroll in less than second entire list
Eddy Vluggen wrote: The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.
I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place.
I do not know it might be some undocumented feature or they are using virtual view.
Eddy Vluggen wrote: rediculous to assume that you're going to read over 500 results,
I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.
Чесноков
|
|
|
|
|
Why not show your design to some users and see what they think of having to scroll through that many items? Get their feedback before you commit to it.
|
|
|
|
|
Chesnokov Yuriy wrote: and event icons are pretty distinct
Not if they scroll by at Mach 2.1
Chesnokov Yuriy wrote: and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events
I have a checkbox for that - a single click and all you see are ListView items with a red cross
Chesnokov Yuriy wrote: while scrolling time column is pretty visible as you scroll it.
I'm off alcohol Laugh that enables me to scroll in less than second entire list
I don't mind scrolling through the event-log, or the log of the profiler, since I'm expecting a list. I wouldn't recommend the same pattern for database-records representing business-objects. But my apologies, you're right, there are circumstances where it might be appropriate
Chesnokov Yuriy wrote: I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place.
I do not know it might be some undocumented feature or they are using virtual view.
It's probably not in .NET. Anyway, there should be a virtual-listview example somewhere on MSDN, give it a try.
Chesnokov Yuriy wrote: I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.
I prefer hitting PgDwn , since it takes effort to move my hand from the keyboard and move it to the mouse. Having "pages" to browse through seems to work for a lot of people, especially if there's a nice index at the bottom. Other people prefer a autocomplete-textbox, or indeed, the scrollbar. Do the Microsoft-thing, and implement 'em all!
I are Troll
|
|
|
|
|
You have been given the same advice from several people now. Why are you continuing to argue the point? If you don't want to use the advice then don't ask for it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: You have been given the same advice from several people now. Why are you continuing to argue the point?
Déjà vu
|
|
|
|
|
Chesnokov Yuriy wrote: Windows Events
Huh? If you're referring to Event Viewer, then yes, I have. And to counter, have you ever looked at ALL of those events, or just the last 100 or so?? Notice how long it takes to populate that list of 1,000 events??
I rest my case.
I know it doesn't freeze. That's because it's adding all those events from a background thread, and not all at one time.
|
|
|
|
|
Dave Kreskowiak wrote: That's because it's adding all those events from a background thread
Yes, Event Viewer, but scroll bar is height is pretty small. There is impression it is naturally populated. It might be in virtual view or manually driven.
Dave Kreskowiak wrote: That's because it's adding all those events from a background thread
I do so also. Once you scroll to a middle it displays events in the middle. It'd be rather complicated to simulate the scroll and show only specific items from the middle.
Dave Kreskowiak wrote: have you ever looked at ALL of those
I did once without problems in PC store when bought a laptop.
I had to quickly browse them all to make sure computer was without glitches.
I do not have any problems. It is easy just to scroll with a mouse to any particular day and then fine scroll with pgup, pgdwn further
Чесноков
|
|
|
|
|
I think you have a complete misunderstanding of how event works. Events happen on demand, when you add 100,000 items all at once, you're simply blocking your application message pump from processing the messages sent by windows (also known as events) and therefore freezing.
It's possible to add this 100,000 items in the control without freezing, as already mentioned, by adding in small iteractions and from time to time, allowing the messages to be processed (one simple, but not usually recommended way to do it is call Application.DoEvents()) and thus not freezing the application.
In any case, I agree with the guys that 100,000 items in a listview is simply insane. It doesn't make sense, nobody want's to see 100,000 items all at once. One approach I like to take is to display a couple hundred at once at the most and have a textbox filtering the results as you type, very easy for the user.
|
|
|
|
|
Fabio Franco wrote: think you have a complete misunderstanding of how event works
You do not know my design. Message pump is independent from the view representation, pump observer. There is no blocking of the pump no matter what the observer of the pump do.
The application freeze only at one point, adding of the list view items to list view, either one by one all of them with AddRange.
Fabio Franco wrote: 100,000 items in a listview is simply insane
There are many customers and you can not develop one solution that suit them all.
I'm one of those wierd ones who fond of scrolling 100,000 events
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: You do not know my design. Message pump is independent from the view representation, pump observer. There is no blocking of the pump no matter what the observer of the pump do.
The application freeze only at one point, adding of the list view items to list view, either one by one all of them with AddRange.
It's not your design, the view representation is totally dependant of the message pumb, read my article: FormEx[^] and perhaps you'll have some idea on how the view get's rendered, it's through windows messages. The application freezes because WM_PAINT message never gets processed by your application because there can be only one UI thread and while you're adding items to your listview, the thread get's dedicated to that alone and has no time to process paint, click and other messages because it's adding the items of the listview, UI operations do not run in parallel. Just do a while(true); on a click of a button and that will also block paint messages and will freeze the app. Add Range and adding one by one are doing the exact same things. AddRange is just to make some operations simpler to the control user. Again, I think you have a complete misunderstanding of how event works.
Chesnokov Yuriy wrote: There are many customers and you can not develop one solution that suit them all.
I'm one of those wierd ones who fond of scrolling 100,000 events Wink
Well, if you're developing this to yourself, I guess there's no harm then, but I really think that's not the best approach if you're developing to a client, I know we can't please them all, but I also know that there are best practices and consolidated designs that pleases the most and I really think your approach is not the most appropriate. But who to know better what your target audience wants but yourself?
|
|
|
|
|