Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP6 DLL giving error in VB6
Message
 
To
20/03/2002 12:10:15
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00634135
Message ID:
00635077
Views:
20
>Hi,
>
>Thank a lot for your advise, it is working now.
>I mistaken the VFP6 compile option of single threads and multi-thread option.
>
>So, what is the different between the instances and threads for VFP compilation
>option ? When do I use single thread and multi thread option in VFP 6 ?
>I thought VB and VFP 6 are both multi-threaded application and we should be
>able to build mult-thread application from it.
>
>Is there any special requirement. ?
>

We probably should go into more theory here. :)

It depends on how do you want to use the COM. As you could see, the Single-Use DLL is pretty much useless (unless there are some specific requirements and conditions to use it).

COM can be compiled as an In-Process (DLL), or an Out-Of-Process (EXE). This affects the way you register it, and there can be a performance difference.

A DLL COM server works in the same process as the COM client (or another COM which instantiated it), therefore all communication happens within the same process.

An EXE COM server, however, works in its own process, so the communication goes across processes, and that's why it is slower. From the client side, running a DLL in the same process also makes the client application vulnerable to server crashes, which is not the case with an EXE server. It is up to you to decide which one to use, but remember that DCOM should be an EXE. It is possible to use a DLL as DCOM, but in that case it has to run under Microsoft Transaction Server (MTS).

You should not mix Multi- or Single- Use for the instancing from Project Info dialog with Multi- or Single- threading from the Build dialog. These are two different things.

If you compile the COM EXE with "Single Use" option selected and create two instances of our object:

oCom1 = CREATEOBJECT("mysample.mycomclass1")
oCom2 = CREATEOBJECT("mysample.mycomclass1")

You will see two instances running in the Task Manager Processes tab. This should not be confused with single user, as in the above sample one user creates two (or more) Single-Use instances of the COM server.
In other words, single user on single PC may create any number of Single-Use COM server instances.

Select "Multi Use" and recompile the EXE. Run two instances of the COM object again and you will see only one instance in the Task Manager.

The value in the Instancing combobox determines how your COM component will be used.
If you choose single-use for your out-of-process COM, each client application will use its own instance of COM server with all the related overhead in creating a new process that you can see in Task Manager and allocating resources for it. However, provided that the PC has enough resources the performance of this component may be better because each process has at least one thread running.

What happens when you select Multi-Threaded COM DLL from the Build dialog?

In a multi-threaded environment the process of the request execution may be interrupted by other requests.

As an example, three client requests arrive to your multi-threaded COM DLL almost at the same time. First request runs some long calculation method in your COM and other two just want to query some COM property.

In a single-threaded environment the last two requests have to wait until the first one is finished, say in a minute and then the other two requests are executed for one second each. So, all three clients got the result in about one minute each. In a multi-threaded environment the long process can be interrupted with others. The result is that for the first long query the execution time will slightly increase, but two short ones are executed almost at once.

So, the multithreaded COM will have a better performance from the user point of view. It does not mean that several simultaneous calls to COM will take less total time. There is still just one processor to execute all calls, plus it needs the time for the thread switching. The real performance increase can happen only on multiprocessor PC.

Note, that programming for multithreaded COM is different from writing the normal code. You supposed to use the SYS(2336) function which can lock and unlock the critical sections of the program where no any interference from other threads, calling the same code, may be allowed. Programming for multithreaded COM also should be a topic for a separate session.

The Multithreaded DLL option first appeared in VFP 6 Service Pack 3 and in order to take advantage of it you are supposed to use a different runtime library - VFP6T.DLL You should refer to the documentation as there is some difference in VFP features supported in normal VFP6R.DLL and VFP6T.DLL
Multithreaded DLL can be used only with "Multi-Use" option, while single-threaded DLL may be both Single-Use and Multi-Use. Multithreaded DLLs is what you should use, for example, for the heavy load web site programming.

You can find more info on the subject in MSDN Library, for example these articles:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fox7help/html/newcontrolling_call_blocking.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/aptnthrd_8po3.asp
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform