|
Hi,
there is nothing fundamentally wrong it what you told here; this could work just fine.
The amount of work is actually irrelevant: when implemented properly the GUI should stay
alive and responsive at all times, and all the work is done, well, in the background.
Now here is maybe a clue: if one of your BGWs is keeping the database very busy
(and if the DB is on another machine, it would not show in your client's CPU activity),
then any other DB request may be delayed for quite some time. Now lets assume something
else in the GUI thread is trying to do a DB access too, that could temporarily
slow down the GUI so it looks frozen, no longer shows the menu bar, whatever.
And that something could be a Window.Forms.Timer doing some simple job periodically...
Of course this is just a hunch; anyway, I suggest you look for an indirect way in which
the GUI gets hampered by the BGW (stealing too many CPU cycles due to thread priority,
stealing DB bandwitdh, a locked object, a locked file, whatever).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Both BGW connect to 2 different Database on different machines.
Process 1 is a fast one but the second is a time consuming one.
It has to check in 11 tables in 1 query. If that gives two rows of result the next agreement has to be found.
I use about 100 queries for determining the proces for 1 DBC in an arraylist.
What I do each time is to add an object in an arraylist. Based on the data in the datareader containing 25 or 1000 lines for proces 2 and 10000 lines for proces 1.
I did create an OnActiveChanged event for the Form and if I add Application.DoEvents(); The freeze get a bit less.
That's all!
Small Test results
I did check the DatabaseServer that will receive the information via Insert INTO sql's.
When I start my program the Database is at 0%. As soon as I hit the Start button the CPU for SqlServer raises up to 40-50%. It stays stable until I press the Cancel button.
My program freezes and the SqlServer user 70-80%........
This is NOT funny
modified on Tuesday, February 26, 2008 11:08 AM
|
|
|
|
|
Hi,
Application.DoEvents() is a dangerous thing, you must make sure you don't call it
recursively (if you do all things may happen, including StackOverflow and less
obvious problems).
When Application.DoEvents() at a particular spot in the code improves the behavior,
that typically means that code that should not execute on the thread it is, but should
be ran by a background thread instead.
What is your OnActiveChanged event? when does it fire, and what is in its handler?
Any idea how often it fires? could it be firing all the time, overloading the GUI
thread with unnecessary work? could it include some delays (say larger than 10 msec,
either a Thread.Sleep or some kind of wait for something)
making the GUI slow but keeping CPU cycles low?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Tuesday, February 26, 2008 11:53 AM
|
|
|
|
|
Deleted the eventhandler for OnActiveChanged. Used it for when Someone click beside the the app and then clicked on the app again. that is the moment of freeze.
removing the eventhandler did not solve....
Seeing in the sql profiler it needs for simple CRUD-work over 13000 reads.....
Time to do some indexing I believe
|
|
|
|
|
Hi,
improving the DB performance is good, but with what you told me, I would say it is
not at the hearth of the problem; your GUI should behave well no matter how fast
or slow the servers are. I still think something is wrong in your client code,
your GUI gets bogged down by something that should not run on or block the GUI thread.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Found IT!
I have 2 dataGridViewComponents and they are refreshed in the ReportProgress events.
Since there are heavy SQL's involved for both dgv's it hang up the app.
I removed these dgv's and their fill ups. It's running smoothy now.
would it be wise to update these dgv's in a timer event (UI Thread!)?
Or better leave them out?
I leaving them out the user cannot see how far the process is.
|
|
|
|
|
Hi,
moving the code that does DB access and DGV update to a Windows.Forms.Timer does not help at all:
the DB access, which is presumably the slow part of it, would block the GUI for as long as it takes.
The right approach would be to split the actions into:
1. some code that does the DB access but does not touch the GUI
2. code that updates the GUI
1. should be organized on a BGW, a thread or a timer (NOT a Windows.Forms.Timer), so it runs
independent of the GUI
2. must run on the GUI
I tend to use some intermediate data structure (say a generic list) to collect results and
prepare them for display (1), then pass it all on to some simple code that updates the GUI (2)
at high speed, hence never blocking the GUI thread and GUI for more than a few milliseconds.
digimanus wrote: leaving them out the user cannot see how far the process is.
It is considered bad design to have a long winding operation that does not report progress
(the user may think the app died); and offering a cancel option (button) is recommended.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hey Luc,
build a 3rd BGW which runs while bgw1 or bgw2 isbusy!
Unless bgw1 or bgw2 has received cancellation pending.
It loads the queryresult in a DataSet.
In the reportprogress for the 3rd BGW the dataset.tables[0] is attachted as datasource to dgv1 and dgv2 (2 datasets, each dgv has it's own).
The user has its view in the progress, sees the statistics run, no GUI Freeze.
Start and Cancel work great.
Thanx for helping me out!
[Added]
Been testing for a while.
You what freezes.... object.Refresh();
Removing that helps a lot in the performance
The project now runs fine on a server some 6 floors lower.
modified on Wednesday, February 27, 2008 9:21 AM
|
|
|
|
|
graag gedaan.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
is there is any simple coding for docking and floating window(Form) in c#....
regards,
ALGATES..
|
|
|
|
|
Hi ALGATES,
You need to do it with a custom control. Take panel control and add the controls you want in it. Then you need to hide/show it on MouseEnter event of the label you're defining.
There are few dockable controls on the market that you can buy if you don't
want to build your own. Also there is something ready on the codeproject:
http://www.codeproject.com/KB/miscctrl/magicdocking.aspx?target=dockable%7Ccontrols[^]
I hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
I'm busy creating an extended ComboBox control, called for now, DropDownList. My reason for the extension is to be able to optionally insert a first item, such as "Add new Customer...", with any data source. I'd like some opinions, please, on how I currently achieve this.
I have a DropDownListItem, which has two properties, ItemType and ItemObject. Then, I hide the base DataSource property, and in its replacement setter, I call a MergeDataSource method. This creates a List<dropdownlistitem>, with one Object type item for each object in the new data source, plus one Prompt type object for the initial "Add new Customer...", and I set the base.DataSource to this new list.
I also hide the Items property, and in the replacement getter, I create a fresh ObjectCollection, but without the prompt items, i.e. only the items from the original data source collection. I see minor potential problems here, as code that expects to manipulate the Items collection will not have access to the actual, current Items collection. However, it is illegal to modify the Items collection while the DataSource property is set anyway. When the DataSource is null, I just return the base.Items property.
|
|
|
|
|
If I understand correctly, you add a prompt type object as the first item. Won't comboBox.Item[comboBox.SelectedIndex] (the new one) returns the wrong item as seen from the UI?
|
|
|
|
|
Yes, that is something I've been worried about. Thanks for mentioning it.
I have never needed to access a selected item through the Items collection, however. I always use SelectedItem or SelectedValue, and I think I could get away with hiding these if necessary. Maybe I should not hide the Items collection, but add another DataItems property that returns the filtered collection.
|
|
|
|
|
No problem, I'm hiding SelectedIndex as well, and returning an offset index that provides correct item in my replacement collection. The 'artificial' entries are completely hidden from the clients of my drop-down, except for the events they raise when selected.
|
|
|
|
|
Oh the joys I had implementing the same thing last year. I did get it finished in the end and they haven't complained yet so I assume it's still working. I'll see if I can dig up the code and modify it (it had some stuff which I can't disclose and which did extra things you won't need). Drop me an email so that I can send you the stuff once I find it.
|
|
|
|
|
I'd like to scroll two richtextbox simultaneously in a Visual studio CLR Windows Form Application, can someone point me in the right direction..
I've tried invoke methods but don't really have much idea about it, i was planning on overriding events is that a good idea.. tnx
|
|
|
|
|
It's really the only idea. You need to catch the scroll event in one textbox, and scroll the other one so it keeps up.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
thanks for you reply, but can you tell me what particular method to use....
i was trying to use invoke methods and here is my code:
#define SB_VERT 1
#define SB_THUMBPOSITION 4
#define WM_VSCROLL 0x0115
[DllImport("User32",EntryPoint = "SendMessage")]
static bool SendMessage(IntPtr hwnd, UInt32 Msg, Int32 wParam, Int32 lPAram);
[DllImport("User32",EntryPoint = "GetScrollPos")]
static int GetScrollPos(IntPtr hwnd, int nBar);
private: System::Void richTextBox1_VScroll(System::Object^ sender, System::EventArgs^ e) {
int a;
a = GetScrollPos(richTextBox1->Handle,SB_VERT);
SendMessage(richTextBox2->Handle,WM_VSCROLL, 0x1000 + SB_THUMBPOSITION * a, 0);
}
I can't determine if the message is really being posted in the message queue is there any way to see that?
The program compiles and run, but they still won't scroll simultaneously.
modified on Wednesday, February 27, 2008 8:43 PM
|
|
|
|
|
After 4 or 5 years in the ASP.NET world I'm about to embark on a new LOB WinForms application and I wondered what the current thinking was in terms of GUI design and implementation?
Any suggestions? I'm severely lacking in inspiration at the moment
Cheers
James
|
|
|
|
|
Look at other applications. I'm doing a very small POS application, so I downloaded MS Office Accounting Express; it's free. Then I looked at the layout of their invoice screen, said I like this but I don't like that, and quickly came up with my own. It's not copying, just looking for inspiration.
|
|
|
|
|
I am using visual inheritance which is really helpful to create uniform design between forms.
|
|
|
|
|
I have several ComboBoxes on a form that are bound to BindingSources. The only code I have is code to set their SelectedIndex properties to -1, to force the user to make a selection, in favour of accidentally using the first item in a list. This code has no effect in my form's Load event, so I have been forced to start a Timer at the end of the Load event, and then on the Timer's Click event, set the SelectedIndex properties. Can anyone explain this, and maybe offer a more elegant solution?
|
|
|
|
|
Insert an "empty/null row" as first item in your source, instead of using -1 to signify value not selected. Have the UI to verify that the combo box has value selected before you save it.
|
|
|
|
|
That was one of my options, but I find setting SelectedIndex a bit tidier that messing with the list domains. Alternatives in this direction are inserting the null value programmatically though, then I would be more comfortable working with an unchanged data source. I would do that in a derived ComboBox control, overriding one of the data binding methods.
I will eventually do that anyway, as I also want a 'Create a new <entity name="">...' as an option in all my drop-downs as well. This must also be 'artificially' inserted and trigger an event that tells the Combo's container to initiate the Create action for that entity.
|
|
|
|
|