Threading with Multiple Forms

bc3tech

Member
Joined
Dec 31, 1969
Messages
13
Location
Ames, IA
Ok heres the general gyst of what im trying to do.

Ive got an ActiveX OCX embedded in my main form that serves as a network browser, showing computers and shares on the local network. Ive 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. Ive done 4 tutorials and downloaded about 3 examples with code. However none of these do quite what im looking for.

When im 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 its working. However, using a thread to call the buildIndex is still rendering my program inoperable for the duration. Ive tried everything imaginable as far as i know and nothings 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! ive 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
 
I dont understand why the activex control raises an event when its done - normally, that would imply that it was executing asynchronously. I would have thought your method would simply return when it was done.

I dont 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) dont play nicely with threads. It may well be putting itself on the main UI thread and wont budge.
 
Originally posted by divil
I dont understand why the activex control raises an event when its 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.
 
Example

Heres 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 thats 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 its doing that.

[edit] Removed binaries from attachment [/edit]
 

Attachments

Last edited by a moderator:
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?
 
Originally posted by divil
Is splitting the intensive code off in to another COM class (i.e. not the ActiveX control) an option?

If youre 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 im probably going to be putting it into my porfolio so I thank you. and hey maybe ill give ya a spot in the About box ;)
 
Originally posted by divil
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 couldnt make head nor tails of how to go about doing this :p
 
That would probably be a red herring anyway, I dont think controls play nicely with each other if theyre 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.
 
I guess Im 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 its 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"? Im not sure what you meant by that.

Thanks!
Brandon
 
VB6.

It uses 2 Classes, though - "NetResource" and "NetResources" and for the life of me I cant 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.
 
Back
Top