Multi-threading in an add-in?

Winwaed
10-18-2007, 09:37 PM
I know VB6 prohibits it, but has anyone had any luck getting a .NET add-in to multi-thread?

My concern is to keep a GUI responsive. With VB6 this can be done using "sleep", which puts the current thread into the window/form's message loop for the set period. The closest sleep call in the .NET world literally halts a thread, which is no good.

Another way might be to force a form to empty the message queue regularly?

Richard

Mattys Consulting
10-19-2007, 06:52 AM
Richard,

Your pardon please - I don't even own VS7 - but the example here:
VB Helper: HowTo: Start multiple threads in VB.NET (http://www.vb-helper.com/howto_net_run_threads.html)
shows Thread.Sleep.

Mike Mattys

Winwaed
10-19-2007, 09:48 AM
Thanks Mike, yes "Thread.Sleep" is what I was referring to as the equivalent in .NET. The problem is that this literally stops the thread for the specified period of time. I want to "process all messages", so I need a sleep that does that in the background. (VB6's sleep() does this).

Following your link led me to go back to the online MSDN docs. There I found Thread.Join which does the required message processing BUT it needs to work on a second thread. So far that isn't working for me, and if I create a second thread then I might as well run the entire dialog box in its own thread (which is what I do in standalone apps).

I'll probably give this a go next, although I know multiple threads in add-ins is prohibited in VB6 and I suspect all add-ins.

Richard

Winwaed
10-19-2007, 12:39 PM
My code is a bit messy still, but it looks like multi-threading is working!!

My approach is to use asynchronous delegates, and you MUST run all MapPoint calls in the add-in's main thread. So my dialog box runs in a second thread as a modal dialog box.


Richard

Mattys Consulting
10-19-2007, 03:12 PM
I was wondering if calling an ActiveX Exe from the addin would work ...
Anywho, congrats! (what addin are you making now?)

Mike Mattys

Winwaed
10-20-2007, 09:47 AM
This is continued development of MPSuperShape. I'm expanding the import options to include .SHP and .MIF files (see my other post elsewhere).

A customer sent a sample file of about 3Meg - it takes a few minutes to load, so I decided a "Working..." dialog box was required.


Richard

 
Web mp2kmag.com
mapforums.com