Rather than using a regular expression, why don't you use the method build into the framework.
//The parent key you want to look at.
RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software");
//All the first level children of the parent key in a string array.
string allSubKeys = rk.GetSubKeyNames();
I've a COM object, which can only be accessed from same thread as created. Some of the COM-object operations are time consuming. If I create that COM-object on the application thread, sometimes the UI freezes (of course) while the object is working. I would like to create and use that COM-object on diffrent than application thread, but I don't know how to do that.
Of course I now how to create threads and stuff, but I don't know how to keep those threads "alive" while no COM-object work is needed. I tried to create new Thread , start it, create a new Control object and access that thread by Control.Invoke(), but that is not working, 'cause the control seems to know the main application thread and decides to run on the main thread instead of thread where it is initialized.
I also tried to use background worker, but I doubt that when worker.RunWorkerAsync() method is called, it runs always on same the thread. It does when I have a simple application, but if there were some other multi threading operation's (in the same application) i thing they would probably use the thread used by background worker(when not working) so the background worker would take other not-used thread from thread pool(if needed) and the COM-object won't work on other thread than the one on which it was created.
I suggest you create a class to encapsulate all operations on that COM object.
Your class can then create a real Thread object (not a BackgroundWorker or ThreadPool thread)
and use that over and over for all the COM operations. You may need to apply some
If your program has an [MTAThread] attribute, you may need to set the thread's
ApartmentState to ApartmentState.STA explicitly. I don't recall all the details here.
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
My app has a layer that fetches objects and stores them in a cache (own implementation). All items are identified by the signature and params of the calling method. This works pretty well. The gui layer uses data binding to bind those cached objects to the controls. If a form ist closed, the user can save or cancel all changes.
The data binding automatically changes the objects that are referenced by the gui AND the cache - even if the user cancels the changes... So the object in the cache is accidentally changed, too. My first idea would be to return only copies of the objects (new references), but how to create a "stand-alone" copy of unknown objects?
Theoretically, you could make the cache use the Memento pattern - without seeing your implementation, it's hard to say, but you could have:
private List<IMemento> _cache = new List<IMemento>
publicvoid AddToCache<T>(T cacheItem)
public T CancelChanges<T>(T cacheItem)
// Get the original item out of the cache and remove it.
T item = _cache[...];
internalclass CacheMemento : IMemento
publicvoid AddToCache<T>(T cacheItem)
// Save this item.
I'm just doing this off the top of my head, so I apologise that it's rough and needs to be tidied up.
Deja View - the feeling that you've seen this post before.
I want to confirm that when using Visual Studio 2005 to build a C# Class Library, the generated assembly Class Library is dependent on .Net 2.0? And for the same case, Class Library generated by Visual Studio 2003 is dependent on .Net 1.1? Could you help to confirm again?
Are thre any ways to change the hard-coded dependencies? For example, in Visual Studio 2005, I could make a C# Class Library which is dependent on .Net 1.1?