|
What does hitting F12 (Go to Definition) on the ObservableCollection show?
|
|
|
|
|
This sounds a bit strange, because this is working for me:
public class CurrencyEntity
{
public bool IsSelected
{
get { return true; }
}
}
This is just a stub, and here's the code:
List<CurrencyEntity> c1 = new List<CurrencyEntity>() { new CurrencyEntity() };
ObservableCollection<CurrencyEntity> ob = new ObservableCollection<CurrencyEntity>(c1.Where(c => c.IsSelected));
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I will try again and let you know. it's very strange..
|
|
|
|
|
Thanks. I think it doesn't work because of Silverlight. I'm using Prism v2 (with multi-targeting feature). so, i need to create the class in SL project and link that class from wpf. that's why the code doesn't work.
Thanks for your help.
|
|
|
|
|
Hi everyone,
I'm experiencing a strange exception in the List<T>.AddRange[^] method.
Sometimes (maybe in 1 out of 100 runs with the same data) I get a System.ArgumentException inside AddRange that the destination array is not large enough for the collection. Here's what I'm doing:
if (itemsToAdd > 0)
{
existingItems.AddRange(itemsToAdd);
itemsToAdd.Clear();
}
Now MSDN clearly states:
If the new Count (the current Count plus the size of the collection) will be greater than Capacity, the capacity of the List<(Of <(T>)>) is increased by automatically reallocating the internal array to accommodate the new elements, and the existing elements are copied to the new array before the new elements are added.
Did anyone else experience this weird behaviour?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Sounds like it is a problem of the allocation of new memory to expand the collection is slower than expected by the framework. Have you tried to set the expected number of elements when you create the List? You may not have an exact number, but an large estimate should prevent this from occurring. The TrimExcess method can free up any extra resources after you've filled the List
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: Have you tried to set the expected number of elements when you create the List?
That's what I will actually try next. But since the error is quite hard to reproduce I'm not sure if this will help. I do have an estimated number how many items the list will contain, so I could set it. It's a very small number of items, so I don't think it's some sort of memory problem (but in this case I think OutOfMemoryException would be the proper one).
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I didn't say it was a memory problem per se. If the framework were trying to place a element into the collection before the memory allocation and redistribution had completed, then it would be an ArguementExcepetion, not an OutOfMemoryException.
only two letters away from being an asset
|
|
|
|
|
This sounds like a valid point. I just wonder if there's something I can do against it apart from setting the capacity myself - but it shouldn't be a real problem, so I think this is fine.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I can imagine two possible causes:
- existingItems or itemsToAdd is accessed from multiple threads and the item count changes during the insertion.
- itemsToAdd implements the ICollection<T> interface incorrectly. What type is itemsToAdd?
Given that you're getting the exception only in 1 of 100 cases, I'm pretty sure that it's the first case: either existingItems or itemsToAdd is accessed from multiple threads.
|
|
|
|
|
Daniel Grunwald wrote: - existingItems or itemsToAdd is accessed from multiple threads and the item count changes during the insertion.
No threads involved (at least none that I know of). However, itemsTooAdd is modified by a different event callback which I have no access to.
Daniel Grunwald wrote: - itemsToAdd implements the ICollection<t> interface incorrectly. What type is itemsToAdd?
It's also a List<T> of the same type.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: No threads involved (at least none that I know of). However, itemsTooAdd is modified by a different event callback which I have no access to.
And on which thread does that event callback run?
Try using "System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);" to see if it runs on the same thread as the rest of your code.
If you use AddRange to add a List<T> to another List<T> and get that exception, I'm pretty sure that the event runs on a separate thread or uses the thread pool.
|
|
|
|
|
Daniel Grunwald wrote: I'm pretty sure that the event runs on a separate thread or uses the thread pool.
You're right:
TID Normal: 1
TID Event: 16
I guess my only solution is to lock the entitiesToAdd , right?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You can't lock an object, you can only lock code blocks.
You have to use a lock around the code in both threads, using the same object as identifier.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: You can't lock an object, you can only lock code blocks.
Yeah, that's what I actually meant. Thanks.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
iam working on vs.net 2005 and iam creating iamges report i have picture box object in tat report and i need to change the picutre in picture object in run time depend on my code so could any one help me
thanks
md_refay
|
|
|
|
|
I may be wrong but AFAIK picture box contents cannot be modified at run time using the version of Crystal Reports that ships with Visual Studio.
|
|
|
|
|
how to do made(draw) 3D(three dimension)plot ?
|
|
|
|
|
Please don't Cross Post and don't SPAM this healthy Sites. Please read forum guide line before post a questions
ghaneie wrote: how to do made(draw) 3D(three dimension)plot ?
Check This[^]
and
Check Draw 3d plot using C#[^]
cheers,
Abhijit
CodeProject.Com MVP
|
|
|
|
|
made plot three dimension
|
|
|
|
|
Congratulations!
Do you have a question or did you just want to share?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hello,
how are you dudes
I have a problem that has been annoying me for quit some time now, and I was hoping that any one can help me with it.
it is as follows:
Let say we have a main form in windows application form and I have on it some text boxes and buttons and so on, and also I have other classes so each class is specialized in doing something.
so I want on of the text boxes to accessible by all of the other class so they can write to it every thing that happen (status, error.. etc).
any ideas ?
if you can provide an example it would be great.
Note: I already post this question in msdn.microsoft.com, but most of the answers was too advanced for me; if it will help this is the link for the question
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/7655aed2-9df2-4558-add7-d741fbd49fc7[^]
Thank you,
Mohammed
|
|
|
|
|
You want to access the controls of another form? You can store those items in an object, or you can use properties to access / change them...
|
|
|
|
|
this is the question ?
|
|
|
|
|
Change the modifier property of your text box to public to get it accessible to all the class.
Now in other class you can access the textbox just like any other class object.
Hope this helps U
With Regards,
B.Ananthvivek
|
|
|
|