|
That would work if the keys are ints. Andrew is correct, I'm looking for a two key dictionary.
|
|
|
|
|
Another possibility is a Collection of Collections. For example, a Dictionary of Keys whose values are another Dictionary of SubKey/Value pairs.
|
|
|
|
|
Yes I was considering that and that may be the best way to go. I don't want to use nested switches because that looks messy.
|
|
|
|
|
Switches?? What switches?? I didn't say anything about any switches.
|
|
|
|
|
Yeah, I'd just suggest nesting two generic dictionaries.
Dictionary<Keycode, Dictionary<Keycode, T>>
Something of that sort...
|
|
|
|
|
Jordanwb,
Will you always know the key and sub values?, or would there be cases where you would only have one value?
If you know both, it might not be the best solution, but you could do "key:sub" as the key for your dictionary.
Just an idea.
Regards,
Gareth.
|
|
|
|
|
The two key types are enums, so yes I would always know.
How does the "key:sub" work?
|
|
|
|
|
I use a Dictionary of Dictionaries.
There is also this[^] article.
Even simpler would be to shift one key "up" and add it to the other. k = a * 1000 + b
But, as I see you also mentioned enums, I'll also mention this[^] article. (If you like that idea, and my comments on it, let me know.)
|
|
|
|
|
Hi,
I have a realtime WindowsForms App updating business object from
a background thread (about 1000 objects). I would like to reflect
the changes in the UI.
I have had a look at INotifyPropertyChanged and BindingList but I am
getting Cross thread exceptions.
What is the best way to handle this?
- backgroundworker or
- new thread with Event wrapper using SynchronizationContext ?
Is it right to create a never ending Background worker (BGW 's
lifecycle = application's lifecycle in my case) and thus monopolize
one of the default 25 threadpool thread ?
Thanks in advance
|
|
|
|
|
reivilos wrote: What is the best way to handle this?
The UI thread should update the business objects. If the background thread needs to tell the UI to update the business object, use a SynchronizationContext and Post to it from the background thread. If you need to spawn a new thread yourself that lasts for the duration of your app, don't use a threadpool thread, create your own.
reivilos wrote: Is it right to create a never ending Background worker
Don't do that, it's not what the BackgroundWorker was designed for. Since it's using a threadpool thread, you certainly shouldn't do this. Create your own thread and make changes to the business objects by Posting to the UI thread's SynchronizationContext.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I am trying to use this DLL in Vista 64 bit version. It give me error (exception)
"BadImageFormatException was unhandled". The same DLL works fine with 32 bit version (Vista). Anyone has come across it, is there a way to resolve it?
|
|
|
|
|
Assuming this dll you're using is one you've built,
When you built the dll, was it built using the AnyCPU platform? If so, you must ensure there are not 32-bit specific references to your code. (Many COM objects, native dlls, 3rd party libs are all 32-bit specific. You may need to obtain 64-bit specific versions of those components.)
Another thing to try is build the dll using x64 as the platform.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Yes it is my own dll and it was built using 'any cpu' option. Also I tried the x64bit but it gave the same error. Sometime it give NotValidEntryPointException, othertimes it gives BadImageException. It work fine on 32bit wondows though.
I am not deep into COM so i do not know what can go wrong there.
|
|
|
|
|
Does your dll use any 3rd party libraries? COM objects? Does it make P/Invoke calls into native dlls?
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Yes it does use third party libraries. I am new to c# so I do not know much about p/invoke but yes it uses p/invoke as well. I do not think it uses COM objects. Again it is working on on 64bit machine (not a vista one).
|
|
|
|
|
Can you post some of your P/Invoke calls? Most likely it's an issue with those.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Here is the format of one such call.
[DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]<br />
internal static extern float a_function(int n, [In] float[] x, int incX);<br />
Thanks.
|
|
|
|
|
Yep, that looks problematic: the first value is an integer. In .NET, this will always be 4 bytes. In native code, however, this will be either 4 bytes on a 32-bit system, or 8 bytes on a 64 bit system (IIRC). Instead of an integer, pass in an IntPtr. Your function would look something like this:
[DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]
internal static extern float a_function(IntPtr n, [In] float[] x, IntPtr incX);
<br />
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I will try it with a new test program to see if it works. Now apparentely the code should work because i am getting error from DLL not from native code. The client program basically does not find the necessary signature or entry point inside DLL. It does not reach the native code part at all. The DLL is just a wrapper of the native code. I will give it a try though and will let you know what happens.
|
|
|
|
|
I'm dealing with my course project. This method handles ListView.SelectedIndexChanged, and al is an ArrayList.
<br />
private void lvFiles_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
al.Clear();<br />
foreach (int i in lvFiles.SelectedIndices)<br />
al.Add(exTree.SelectedPath+lvFiles.Items[i].Text);<br />
}<br />
I want to collect the selected items in ListView when event SelectedIndexChanged is triggered. But I always get an ArrayList that contains two copies of selected items, just like this:
AAAAAA
BBBBBB
AAAAAA
BBBBBB
But what I want is:
AAAAAA
BBBBBB
I'm totally confused....Can anyone explain this? Many thanx....
|
|
|
|
|
I'm not sure what could be wrong, the problem might be somewhere else. Try putting a break point on al.Clear() and step through the foreach loop checking the contents of al each time in the debugger. If you find that by some strange reasoning everything is getting added twice in the loop, then you can try a slightly different loop, like:
foreach(ListViewItem item in lvFile.SelectedItems)
al.Add(...);
or something.
Its always possible that items are getting doubled up somewhere else, so use the debugger to find out whats going on.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi,
I can't explain the doubles, every time you add or remove an item to the selection,
the event will fire but since you always clear the ArrayList that should not cause
wrong results.
However I do suggest you use SelectedItems instead of SelectedIndices, it will yield simpler code,
skipping all the index stuff.
|
|
|
|
|
natsuyaki,
Add some Trace'ing so that you know how many items are selected, and then how many items are added to the arraylist and what those items are.
Also, if you're using .NET 2.0 upwards, i'd change the arraylist to a generic list, just makes life easier.
Regards,
Gareth.
|
|
|
|
|
Where do you create a new arraylist ?
Is there a chance that you are creating a new copy each time hence having more than one instance of al ?
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
How do you determine what the ArrayList contains?
Are you stuck with framework 1.1? Otherwise you should use a List<string> instead of an ArrayList.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|