|
When I click the button on the winform to populate teh listbox with data, the form freezes and therfore do not see the listbox when data is being added to it.
When the population is done, only then the form is NOT frozen any longer and then I can see the data inside the listbox.
Is this to do with threads?
How do I solve this so that I can see the data as they are being added to the listbox?
Thanks
|
|
|
|
|
Yep, the populating is done in the GUI thread. The easiest way to solve this is by using a BackgroundWorker. Put the code for the population in the DoWork event of the BackgroundWorker and just start the BackgroundWorker when clicking the button.
|
|
|
|
|
You can't do this.
winforms controls can only be updated from the GUI thread.
Either do the processing on a background thread, and call to the GUI thread to update in batches, or do what Ashfield says and do all the processing before you update the listbox.
Simon
|
|
|
|
|
arkiboys wrote: Is this to do with threads?
Yes, your UI thread is tied up with populating your listbox
arkiboys wrote: How do I solve this so that I can see the data as they are being added to the listbox?
It doesn't make sense to do this really, the user cannot access the listbox until its fully populated so why show them it partially done? To keep the form responsive you could use a background thread to populate a collection of some type (say a datatable) and then just bind this to your listbox, but the user will not see the listbox contents until they are fully populated.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
The job takes aboout 4 hours to complete.
Data gets added to the listbox and so I would like the user to see what is being added...
Is there a way so that the user sees the listbox being populated?
|
|
|
|
|
arkiboys wrote: Is this to do with threads?
Kind of.
You are obviously doing a lot of stuff in the button click event handler.
A standard winforms app has a GUI thread which does all the form drawing and event processing. When you click the button, that thread triggers the event handler. If you then do a lot of time consuming work in the event handler, the GUI thread is tied up so can't do any other work, like redrawing the list box or processing other button clicks. What you need to do is do any long running tasks on a background thread. The easiest way to do this is with a BackgroundWorker[^]
One of the quirks of winforms is that only the GUI thread can actually update any controls. This means that you will need to do your complex calculations on the background thread, but switch back to the GUI thread to add the items to the list box. You use the Invoke method on the form to call code on the GUI thread.
if(this.InvokeRequired)
{
dosomethingdelegate dsd = new dosomethingdelegate(dosomethingmethod);
this.Invoke(dsd, anyParametersGoHere);
}
To do this, I would group them up into blocks, do the processing on the background thread, then call a method to add several at a time using the ListBox.Items.AddRange method on the GUI thread. This will also reduce the number of repaints of the list box that the app needs to do, so will improve it's performance.
Simon
|
|
|
|
|
Simon Stevens wrote: this.Invoke(dsd, anyParametersGoHere);
I'd go with BeginInvoke as it returns immediately without waiting the control to be updated. BeginInvoke is safe unless you pass reference parameters to the method which updates the control.
|
|
|
|
|
|
how fill gridview from datatable or how set conntent of datatble on the gridview Web C#
zz
|
|
|
|
|
Datasource and databinding. Ever heard of the HELP facility in visual studio?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
|
Hi friend can any body tell me about .pfx file. and why we need ti use it in project and what is it advantages.
wasim khan
|
|
|
|
|
Why didn't you use Google for this question? Seriously, why? It's taken you longer to ask this question than it would have taken for you to google pfx file. It's a personal information exchange key, and contains a public and private key. One place you need this file is in ClickOnce.
Seriously though - Google it and read up on it. It does so much more.
|
|
|
|
|
Hi,
everybody how can merge three liste Of int in csharp.
Exemple:
List<int> Audios;
List<int> Videos;
List<int> Books;
list<int> All;
the list ALL must contains the merge of the three list, the question is can we do with out using foreach statment for the thre list.
thankx
|
|
|
|
|
you can use the AddRange method to add the whole of one list's contents to another.
List<int> Audios = new List<int>();
List<int> Videos = new List<int>();
List<int> Books = new List<int>();
List<int> All = new List<int>();
All.AddRange(Audios);
All.AddRange(Videos);
All.AddRange(Books);
Simon
|
|
|
|
|
papy-boom wrote: the list ALL must contains the merge of the three list, the question is can we do with out using foreach statment for the thre list.
Well, you can call methods that does it for you, but there is no way to merge entire lists. The items has to be added one at a time whichever method you use.
The most efficient way is to create a list with a specific capacity, that way it doesn't have to be resized while the items are added:
List<int> all = new List<int>(audios.Count + videos.Count + books.Count);
all.AddRange(audios);
all.AddRange(videos);
all.AddRange(books);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi All
I’m trying to make a list view to catch multithreads. I have a tree view on the right and the list view at the bottom. i want to find out how to display what has been open in the MDI. E.g. if I open a form called email using the treeview I it should display the details that I opened the email form in the list view. It is something like Microsoft Dynamics SL -Solomon
I am very new at c#
|
|
|
|
|
Do you mean you do something on the form (or the TreeView), and then some backend processing happens in a thread and when the results come the ListView gets updated? If so, use BackgroundWorker helper class in the System.ComponentModel namespace.
-------------------------------------------
It's code that drives you - Shyam
|
|
|
|
|
I want to get RTC(Real time clock) time in c#.
How can i do that? Thank for your answer.
|
|
|
|
|
|
I think System.DateTime.Now is OS time not RTC time.
|
|
|
|
|
Where do you think the OS gets it's time from?
The RTC is a bit of hardware that keeps track of the time while the PC is powered off. When the PC is powered on again, the time in the RTC is loaded and used by the OS.
Depending on the OS, it may then rely on the RTC to count the time, and make a call to the hardware when over the time is needed, or it may keep track of the time using itself a software clock/counter.
Either way, the value you get returned to you is the current time as far as the system as a whole is concerned. There is no need to distinguish between "OS time" and "RTC time" one is simply used to back the other.
Unless you have a very strange and unusual requirement where you must have the actual hardware RTC value, just use DateTime.Now.
Simon
|
|
|
|
|
I have the follwing Problem. We have developed an application for a mobile device using windows mobile 5 as operating system. In the next step we want to install new versions of the software but we neet to uninstall the old version first. Since we don't have Active Sync all the time, and we don't want the user to uninstall the software over the systems>remove programs.
I'm just looking for the exe which is capable of removing applications from the mobile device, similar to msiexec.exe on other windows based systems. And then using c# code to remove/uninstall the application.
Any ideas?
|
|
|
|
|
Hi..
I need to get the List of all the user Name from Active Directory, i used the following code.
try{
ADEntry = new DirectoryEntry("LDAP://" + Session["DominName"].ToString() + ".net", txtUserName.Text.ToString(),
txtPassword.Text.ToString(), AuthenticationTypes.Secure);
nativeObject = ADEntry.NativeObject;
}
catch (Exception)
{
DirectorySearcher mySearcher = null;
mySearcher = new DirectorySearcher(ADEntry);
mySearcher.SearchRoot = ADEntry;
mySearcher.Filter = "(&(objectClass=USER))";
mySearcher.SearchScope = SearchScope.Subtree;
mySearcher.PropertiesToLoad.Add("SAMACCOUNTNAME");
mySearcher.PropertiesToLoad.Add("cn");
mySearcher.PropertiesToLoad.Add("mail");
SearchResult srh = null;
srh = mySearcher.FindOne();
int intSerialNo = 1;
foreach (SearchResult resEnt in mySearcher.FindAll())
{
resEnt.Properties["SAMACCOUNTNAME"][0].ToString();
resEnt.Properties["cn"][0].ToString();
resEnt.Properties["mail"][0].ToString();
}
But it is listing Max 1000 users details but there are 2000 entries in the ADS under "user" group..<br />
<br />
<br />
Please anyone Help me to get the list of all the 2000 user's list in ADS..<br />
<br />
if there is a limitation for LDAP protocol.. Can any one suggest other protocol, i tried with WINNT, NDS and IIS also..<br />
<br />
<br />
|
|
|
|
|
Yes, LDAP has a limit of 1000 result for a single search. To avoid that you must perform a paged search.
To do that, just set the PageSize property of the DirectorySearcher object to a value greater than 0 (e.g. 500 or 750) before calling the FindAll method.
The MSDN documentation for that is Here[^].
|
|
|
|