Solved

single or multiple threaded AND syncronisation

Posted on 2003-11-13
3
537 Views
Last Modified: 2012-06-27
Ok, so I was under the impression that vb is single threaded correct?

well the scenario is thus...

We have a VB application, say "Reciever",
We have many instances of another VB application, say "Client"
We also have a VB COM+ "Event Server" application.

So the client calls a method on the Event Server which fires an event on the Reciever.
This event is handled and carries out some manipulation on the apps members.
In the mean time the app is carrying out its main line of execution.

While stepping through the main code, if an event is fired then the current line will jump to the event code.

So this would say to me that Reciever is multi threaded...

Anyway, when there are multiple Clients running, we get an automation error (-2147164155 OR 8004e005).
So we tried utilising Critical Sections to lock access to the array while in use.
When the main code is executing, we get a lock on the Critical Section and release it at the end of this iteration of the code.

When an event comes in, it attemps to get a lock and in theory has to wait until the lock is released by the main code.
In practice though the lock is granted which means it is implied that the event is in the same thread.

Chicken and egg has nothing on this!

how can we ensure cross-'Thread' sync'ing?
is vb truly single threaded?

m3
0
Comment
Question by:monkey3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Z_Beeblebrox earned 250 total points
ID: 9741431
Yes, VB is in general single threaded. The behaviour you describe can be caused by something called re-entry. What can happen is whenever you make an out-of-apartment call (typically an out-of-process call, like to SQL server or to a COM+ component) any outstanding events that are waiting for that thread can be processed, which gives the impressing that two functions are executing simulatenously. But they are not, its just that the first one was interrupted part way through, and the second one took over. This is why the critical section approach doesn't work, because it is the same thread, as you said.

This can be very problematic to deal with. One thing to do is try to avoid making any out-of-apartment calls when your variables are vulnerably to re-entry. If that can't work, then you may need to implement your own protection scheme, have a boolean that says if the variable is locked, then in your event handler, put in a loop until the boolean is cleared with a DoEvents.

Zaphod.
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9747874
monkey3,
    VB is normaly single threaded, but there are workarounds to do multithreading if you really really need to. Z_Beeblebrox's description does answer what you specificaly described in your question though.

http://www.freevbcode.com/ShowCode.Asp?ID=1287

Dang123


0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 16 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question