bc3tech Posted March 5, 2003 Posted March 5, 2003 Ok here's the general gyst of what i'm trying to do. I've got an ActiveX OCX embedded in my main form that serves as a network browser, showing computers and shares on the local network. I've written a method into this called buildIndex() that goes thru and enumerates all the computers and shares and writes them to a text file. All this works fine. The problem is coming when I call this buildIndex function within my program, the whole thing, as you might imagine, locks up completely as it scans the network and writes out to the file. You can begin clicking again when the indexing is complete. So naturally, i have looked all over for threading information. I've done 4 tutorials and downloaded about 3 examples with code. However none of these do quite what i'm looking for. When i'm building this index, I have another form that i put on top of the main one that says "building index..." and has a progress bar that just scrolls itself to show that it's working. However, using a thread to call the buildIndex is still rendering my program inoperable for the duration. I've tried everything imaginable as far as i know and nothing's working!!! ideally these are the steps that need to happen: 1) call the buildIndex function of the ocx object into a thread to operate asynchronously 2) display frmIndexing, and have the progressbar (run by a timer) going as the indexing is occuring 3) upon the flag of the indexBuilt event in the ocx object, stop the timer on frmIndex, and close frmIndex. All the while i need to be able to still be clicking around the program if at all possible. if you have any ideas please let me know! i've messed with delegates, thread(), threadstart(), begininvoke(), and invoke() from both sides (all executed on frmIndex, or all on frmMain, as well as mixed) THANKS! Brandon Quote
*Gurus* divil Posted March 5, 2003 *Gurus* Posted March 5, 2003 I don't understand why the activex control raises an event when it's done - normally, that would imply that it was executing asynchronously. I would have thought your method would simply return when it was done. I don't know why calling that method in a new thread would still lock up your program, but I have heard that ActiveX controls (and any UI control for that matter) don't play nicely with threads. It may well be putting itself on the main UI thread and won't budge. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bc3tech Posted March 5, 2003 Author Posted March 5, 2003 I don't understand why the activex control raises an event when it's done it does this cuz i wrote it to do so after reviewing another example. the example used events and handlers to run me.beginInvoke w/ the main form when they were triggered so i threw an event into my ocx to do the same thing... still no soup, though. Quote
bc3tech Posted March 5, 2003 Author Posted March 5, 2003 (edited) Example Here's basically what I need it to act like, however if you notice this does not do it between controls on forms or having a new form doing operations while the main one does. I think that's where my problem is. Take a gander at this, put in a large number (like a million) to the text box, click run a loop, then click any of the other buttons while it's doing that. [edit] Removed binaries from attachment [/edit]multithreading tutorial.zip Edited March 5, 2003 by divil Quote
*Gurus* divil Posted March 5, 2003 *Gurus* Posted March 5, 2003 Thanks, I knew what you were trying to do. My personal feeling is that the ActiveX wrapper is automatically shifting to its owner thread (the UI thread) when you call methods on it. This makes sense to me, and I asked someone else who agreed. You might be able to create the ActiveX control on a new thread, that would probably fix the problem but I doubt it would want to be parented to your form in that case. Is splitting the intensive code off in to another COM class (i.e. not the ActiveX control) an option? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bc3tech Posted March 5, 2003 Author Posted March 5, 2003 Is splitting the intensive code off in to another COM class (i.e. not the ActiveX control) an option? If you're asking if i could write the buildIndex function in another spot I think it may be possible.... is that what you would suggest? putting the buildIndex function as a sub w/in frmMain and calling that with a thread?? Would that still allow for the redrawing of the form when i click menus, open new forms, etc etc?? I appreciate your help immensly. this is a semester project and i'm probably going to be putting it into my porfolio so I thank you. and hey maybe i'll give ya a spot in the About box ;) Quote
bc3tech Posted March 5, 2003 Author Posted March 5, 2003 You might be able to create the ActiveX control on a new thread, that would probably fix the problem... I had thought about doing this too, if i could just have the control running in its own thread, but couldn't make head nor tails of how to go about doing this :p Quote
*Gurus* divil Posted March 5, 2003 *Gurus* Posted March 5, 2003 That would probably be a red herring anyway, I don't think controls play nicely with each other if they're on different threads. What I was suggesting was to move your BuildIndex function in to an entirely different class. I assume if you were in the position to write it in .net (most preferable) you would have done so. So my thought was to make another public class in the same library as the ActiveX control, and stick the BuildIndex function on that. You could use internal properties if you need to share data between the two. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bc3tech Posted March 5, 2003 Author Posted March 5, 2003 I guess I'm a little confused as to what you just said. I have been trying to convert all the VB6 code that this OCX was written in over to VB.NET for the past little while and it's proving to be a real pain. So yeah can you give me more direction on how to put this buildIndex into another class w/in the ActiveX "library"? I'm not sure what you meant by that. Thanks! Brandon Quote
*Gurus* divil Posted March 6, 2003 *Gurus* Posted March 6, 2003 What language is this ActiveX control written in? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bc3tech Posted March 6, 2003 Author Posted March 6, 2003 VB6. It uses 2 Classes, though - "NetResource" and "NetResources" and for the life of me I can't get them converted to .NET. I can get the actual code for the ActiveX control over, but the classes are proving to be the difficult part. Quote
Recommended Posts