Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Single-threaded Apartment (STA)?


Hi all,

What is single-threaded apartment (STA)?
And why does a VB programmer need to know about it?

Regards,
Saran.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Single Threaded Apartment Model
can u please explain about single threaded apartment model in visual basic (default model of active x dll's in vb6)

Apartment Threaded DLL.
I have designed a ACTIVEX DLL in VB 6.0.
The threading model that i have used for this is the "Apartment".
Please let me know if i can use this in a multithreaded client.

regards,
Diwakar

Gudiance Please: Why Use Apartment Threaded Model When Compiling A UserControl?
What is the advantage/disadvantage to selecting apartment threaded model versus single thread model from project properties when compiling a User Control?

I'm not sure I understand threads. (Actually, I'm pretty sure I don't). From what I gather, threads are the channels through which event messages are sent between the computer and your code -- is that right? Am I unable to support multiple instances without MTA Model?

Single Threaded Processes?
Hello

I am developing an application to take an alarm message either from a serial port or from a network socket.

My question is if I have a timer that checks for serial messages and a Winsock connection event that both use a common sub procedure to process the message, what would happen if both are triggered at exactly the same time? Would the messages be queued someone by VB or would messages get missed?

E.g. code




Private Sub TimerCheckBuffer_Timer()

LittleBits = ComPort.InBufferCount

If LittleBits >= 37 Then

RawMessage = ComPort.Input

Call Translate(State, ALUID)

End If

End Sub

Private Sub WinsockIn_DataArrival(ByVal bytesTotal As Long)

Dim strData As String

WinsockIn.GetData strData, vbString

Call Translate(State, Code)

End Sub

Private Sub Translate(State, Code)

' Do lots of processing of message

End Sub


Another question is, what happens to the triggering events while VB is following my Translate sub and processing the message? Are they ignored or queued?

Any help or clarification would be very much appreciated.

Thanks again.

IIS && .NET Web Service Single Threaded???
I am working on a heavy web application, one that can take a few seconds for a users data to be returned. And one thing I have noticed, that when ever one user is doing something heavy, or something that stalls the server (the web app is waiting on SQL to respond), it stops all other traffic that is .NET based.

This is NOT cool at all. Is there ANY way to fix this other than having a users page refresh (like once a sec while SQL is working) and putting those SQL calls in another thread?

Is there no way I can have the application give a new thread to each user?

I can stack the SQL calls, but UUUUUUG that is a big pain.

ActiveX EXE Being Forced To Single Threaded ? Help Please ?
Hi all,

I have searched hi and low, here and the www but I cannot find even a small hint as to the source of this problem :o

I have an application that creates references to a multiuse object contained within a thread-per-object ActiveX EXE. The multiuse class utilises a timer to provide a pseudo-async/multi-threaded execution model.

The application has installed and worked perfectly in over 100 instances, across just about every OS and service pack combination you can think of. However, I now have 2 sites where the application just will not run as expected :(
In both instances the application is installed on a Windows2000 Server.

What appears to be happening is that the timer control (used to generate a pseudo-thread) is only raising its event into the last object created. e.g.

Instance1 - working fine
add Instance 2 and Instance1 stops working ?!

I have found that I can workaround the problem by changing the multiuse interface on the ActiveX EXE to singleuse and recompiling. Thus a completely seperate process is spawned for each instance of the object that uses the timer.

Can anyone tell me why a change from multiuse to single use should effect the ability to receive events from a timer control ?

I don't want to rollout singleuse-thread-per-object everywhere as the machine resource requirements go through the roof !


Single Threaded Applications Using Multithreaded Ocxs - Problems?
Lets say i had 400 winsocks on my form. these winsocks were in an array, and in each data_arrival event, id pass the data to a 'handlepacket' sub which would determine what was received, and how to respond to it.

the problem is, each winsock is in its own thread. .you can do stuff and execute code in your main form even while winsock is working or doing something..
but with 400, a lot of data comes in rapidly.

if the many threads of winsock try to access the same sub in the single threaded 'main' app, will problems occur? will the sub be hit twice at the exact same time, and cant handle the request? will the sub be asked to execute by one thread, while its already executing data from another?

will the same memory pointer be accessed at the same time?

i have no idea what would happen..

anyone know? is this a safe thing to do?

Single Threaded Applications Using Multithreaded Ocxs - Problems?
Lets say i had 400 winsocks on my form. these winsocks were in an array, and in each data_arrival event, id pass the data to a 'handlepacket' sub which would determine what was received, and how to respond to it.

the problem is, each winsock is in its own thread. .you can do stuff and execute code in your main form even while winsock is working or doing something..
but with 400, a lot of data comes in rapidly.

if the many threads of winsock try to access the same sub in the single threaded 'main' app, will problems occur? will the sub be hit twice at the exact same time, and cant handle the request? will the sub be asked to execute by one thread, while its already executing data from another?

will the same memory pointer be accessed at the same time?

i have no idea what would happen..

anyone know? is this a safe thing to do?

Single Vs Multi Threaded Object Using Visual Basic ActiveX COM Programming
Hi there folks,

I have a serious question here, is Visual Basic able to do a mult-threaded ActiveX COM object? I heard people from Goggle groups saying that only Visual C++ under MS roof of development can do that job rite?

I need solid proof and technical paper to support this if yes. Otherwise if no, then also need solid proof.

Appreciated it!


 

Threaded Apprlication Vs Non Threaded Application
What are the merits and de-merits of Threaded application over Non threaded Application.?

VB Apartment Threading
Could I use VB apartment threading to control incoming data from 32 modems? I would want 1 thread per modem with a box displaying the details of the communications for each modem.

Re : Apartment Threading In VB
1. I have an object call cls Background and a function call StartBackgroundThreadApt as below :

Set qobj = New clsBackground <This is declare at the Modules as global variable>

Public Function initBackgroundThreadApt(ByVal strEmployeeID As string)
clsBackground.setEmployeeID = strEmployeeID
StartBackgroundThreadApt qobj
End Function

Inside StartBackgroundThreadApt, I do the following :

res = CoMarshalInterThreadInterfaceInStream(IID_IDispatch, qobj, threadparam) /* Trying to create some proxy obj
to access qobj.*/
If res <> 0 Then
StartBackgroundThreadApt = 0
Exit Function
End If
hnd = CreateThread(0, 2000, AddressOf BackgroundFuncApt, threadparam, 0, threadid)

Qns : If I call initBackgroundThreadApt a couple of time with new strEmpolyeeID values, and each call to StartBackgroundThreadApt function I create a thread to handle this new strEmployeeID values, it does not seen to work? What's wrong. Thanks.

Apartment Threading
Please can any one explain exactly how apartment threading works because the concept is not clear to me?

Apartment Model
Can i open new Apartment for my objects in ActiveX Dll (VisualBasic)? Where objects, for example, PowerPoint application...

Thanks
Konstantin

Winsock Multithreading (Apartment Threading)
As everyone knows, all ActiveX Controls run in their own apartment thread. My concepts of multithreading are pretty clear in C++ but I am having some difficulties understanding how VB handles multithreading or does it just stack up events and put them in queues?

My question is based on Winsock. I am creating a server in VB that will be handling multiple connections that would go over 1k. Obviously my server might and will be receiving data from hundreds of client programs simultaneously. In my understanding, what VB does is stacks up each event in a queue and handles one event at a time. However someone told me that VB can handle multiple events at the same time. So basically if my DataArrival event had some code for writing to a file.... that means if VB can handle events simultaneously, it will write to the file simultaneously, right? Or according to my understanding, the events will be stacked up and executed one at a time??? Could some please shed some light on this

Thanks

Apartment-Model Threading In Visual Basic
Can anyone explain?
Thinker????
http://msdn.microsoft.com/library/en...l/avtcm097.gif

Visual Basic+apartment Threading Model
Dear Users,

I am using visual basic 6.0 on windows 2000 professional edition, and i made the following program:

//project type: activex EXE
//start mode: standalone

//at a module

Code:
Option Explicit

' Structure to hold IDispatch GUID
Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Public IID_IDispatch As GUID

Declare Function CoMarshalInterThreadInterfaceInStream Lib "ole32.dll" _
(riid As GUID, ByVal pUnk As IUnknown, ppStm As Long) As Long

Declare Function CoGetInterfaceAndReleaseStream Lib "ole32.dll" _
(ByVal pStm As Long, riid As GUID, pUnk As IUnknown) As Long

Declare Function CoInitialize Lib "ole32.dll" (ByVal pvReserved As Long) As Long
Declare Sub CoUninitialize Lib "ole32.dll" ()

Declare Function CreateThread Lib "kernel32" (ByVal lpSecurityAttributes As Long, _
ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, _
ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, _
lpThreadId As Long) As Long

Declare Function GetCurrentThreadId Lib "kernel32" () As Long

Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Private Sub InitializeIID()
Static Initialized As Boolean
If Initialized Then Exit Sub
With IID_IDispatch
.Data1 = &H20400
.Data2 = 0
.Data3 = 0
.Data4(0) = &HC0
.Data4(7) = &H46
End With
Initialized = True
End Sub

Sub Main()
Load Form1
Form1.Show
End Sub

Public Function BackgroundFuncApt(ByVal param As Long) As Long
Dim qobj As Object
Dim qobj2 As Class1
Dim res&
' This new thread is a new apartment, we must
' initialize OLE for this apartment (VB doesn't seem to do it)
res = CoInitialize(0)
' Proper apartment modeled approach
res = CoGetInterfaceAndReleaseStream(param, IID_IDispatch, qobj)
Set qobj2 = qobj
qobj2.DoCount 1000

' Alternatively, you can put a wait function here,
' then call the qobj function when the wait is
' satisfied

' All calls to CoInitialize must be balanced
CoUninitialize
End Function

' Start the background thread for this object
' using the apartment model
' Returns zero on error
Public Function StartBackgroundThreadApt(ByVal qobj As Class1)
Dim threadid As Long
Dim hnd&, res&
Dim threadparam As Long
Dim tobj As Object
Set tobj = qobj
' Proper marshalled approach
InitializeIID
res = CoMarshalInterThreadInterfaceInStream(IID_IDispatch, qobj, threadparam)
If res <> 0 Then
StartBackgroundThreadApt = 0
Exit Function
End If
hnd = CreateThread(0, 2000, AddressOf BackgroundFuncApt, threadparam, 0, threadid)
If hnd = 0 Then
' Return with zero (error)
Exit Function
End If
' We don't need the thread handle
CloseHandle hnd
StartBackgroundThreadApt = threadid
' This message box can cause problems
' MsgBox "New thread created " & threadid
End Function

//at a class module
//class name: Class1
//databinding behavior: vbnone
//instancing: publicnotcreatable
//presistable: notpresistable


Code:
Public Function DoCount(ByVal final As Long)
Dim v As Long
v = 0
While v <> final
v = v + 1
Wend
MsgBox "end"
Dim b As New Form1
b.Show
End Function

//at a form

Code:
Private Sub Command1_Click()
Dim c As New Class1
StartBackgroundThreadApt c
End Sub

the problem is when i run the program from the visuala basic IDE, it works correctly without any error using the multithreading apartment model, but when i make the exe file and try to execute it, it fails.
can anyone tell me if i should make any specific configuration before making the exe file?
i am really experiencing
and thanx for any help

Nizar Handal

Access Database Setup - Apartment Management Software
I currently manage around 10 Apartment buildings and I'd like to create a small application that will help me manage efficiently rather then using basic excel spread sheets. The first problem that I run into is the creation of the actual database in Access. I'm not really sure how to link tables together and what would be the best way to catagorize all data.

For example.

Table 1 - Building INFO

*Building ID
Building Address 1
Building Address 2
City
State
Zip
# Units
Description
Manager
# of parking spaces

*Manager ID
Manager First Name
Manager Last Name
Manager Address 1
Manager Address 2
City
State
Zip
Manager Phone
Manager Cell phone
Manager description
Manager warnings
description of each warning

* Building 1 Unit 1
# of rooms
status (vacant/not vacant)
description
balcony (yes/No)
parking spaces
tenant info
rent
# of people living

this is a very generic and basic sample of the data that I would need. This project will get very indepth in details and I'd like to find someone that is interested in helping me with the database setup. And maybe in the future we could work on an application for this.

Summary: Can anyone help me with setting up the database for my needs? I have no idea how to tie a Tenant to a specific Apartment with a specific rent ($700). And then have another tenant move in 1 year later at $800 without messing up data. I'm just so confused on this.

Threaded Calls
What is the simplest way to make a call to a blocking function in a thread so it doesn't hold up the program?

Threaded Programming
Is it possible to do thread programming in vb as we do in java.

Actully I have to generate doc document as a report. but it is taking very long time for which application get halted.

only if i can run this process as back ground process. user cab be able to do some thing else.

also is there any way user can halt this on going process in between .

thanks in advance

What Is 'multi-threaded' ?
Hi,

I often hear ppl saying multi-threaded or multi-thread applications from time to time. But can anyone tell me what exactly is a multi-threaded program?

thnx in advance

Multi-Threaded App
hi all,
does anyone no know, how can i go about writing a multi-threaded app in vb (i am using vb6),

i thought making a group project,
(standard exe and activex dll)

and then calling the functions in the dll
asynchronously, will do the work in the background,
executing as seperate thread than the ui (exe).

but it holds up the main thread (ui) (exe),
until the activex dll has finished doing the work,

any suggestions????

Multi-Threaded Chat
bit of background, im writting a chat program (basically as a learning tool before i start work on a game)..

i have all the basics set up, the winsock controll array etc.. all is working good..

im wanting to have a seperate array that contains the user information for each socket..

so like.. (not using vb tags as im doing this freehand)

Dim UserData() As String

Socket(1) = UserData(1)
Socket(2) = UserData(2)

that i can do, and its no problem.. i just need a few questions answering..

first one.. how can when i run though the whole array skip any that are missing, i get errors if i try to get anything from say UserData(2) if its value is nothing.. would using Each in the For loop solve this? and if so, how would I go about using it!?

second question, is it possible to use variables such as:

UserData(1).Password = blahblah
UserData(1).Username = blahblah
etc. etc..

thanks alot for the help..

andy

Playing A Threaded AVI File
Anyone know how to do this? Preferably using no third party controls.

Threaded Application DeBug Help
I have minor problem, ok a big problem. I am attempting to create a mutli-threaded application. I have the application working to a certain extent. I can run the application perfectly if I run it through the IDE. When I compile it, it will run but crashes when I send it information. The jist of the projects is this,

When someone posts to a web site, I want this program to activate and do some processing. Since I may actually get several hits to the site in rapid order, I wanted this to be multi-threaded. This code listens on port 11000 for a connection attempt. When the attempt comes in, a new thread is created (and right now it just shows a message box) and closes the connection, and re-initializes for the next connection.

Since this crashes right after a connection attemp, I am thinking I need to do something with the new thread created.

I know they say to not do threads in VB, but I wanted to try this before I went to something else.

So if anyone wants to have a go at the code please feel free.

Thanks in advance.
Roger

What's A Multi-Threaded Component?
Hi,

I have seen some people saying about Multi-Threaded components. What does this mean?

Thanks in advance...

Michel Jr.

Some good Activex controls at my HP:
http://www.geocities.com/michel_junior_hp/index.html

How To Create A Multi-threaded Application In VB6
Good day, Gurus!

I just want to know how can i create a multi-threaded application in vb6.
I've been using timer to implement such multi-threaded application but it seems that my application is still a single threaded one.

Thanks in advance!

Multi-threaded Async Cancel
I'm trying to write an ASP page with VBScript or JScript that will execute some async operation (thread1) and then from another thread (thread2) cancel the operation of thread1. Any ideas on how to do this without loading a COM dll?

Multi-threaded Idle Timer
I have some code for an idle timer, but the problem is that it doesn't leave the function untill the time is reached. So if the user sits idle the program doesn't go any further! I want to put it in a thread and have it run in the background always- so one thread can stay in this function and the other can run the program. I know a little about threads in general but don't know anything about threads in visual basic. Any tips- Keep it simple!

Code:
Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long

Private Const QS_KEY = &H1
Private Const QS_MOUSEMOVE = &H2
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)

Public bCancel As Boolean
Public Sub CheckInputIdle(ByVal TimeOut_InSec As Long)
  Dim t As Long
  t = Timer
  Do While bCancel = False
    If GetQueueStatus(QS_INPUT) Then
       t = Timer
       DoEvents
    End If
    If Timer - t >= TimeOut_InSec Then Exit Do
  Loop
  If bCancel = False Then
    MsgBox "Process idle is for " & Timer - t & " sec."
  End If
  CheckInputIdle 5
End Sub

'======Form code (or Sub Main())===

Private Sub Form_Load()
  Me.Show 'Force to show window
  CheckInputIdle 5
End Sub

Private Sub Form_Unload(Cancel As Integer)
 bCancel = True
End Sub

Creating Muti-threaded Component In VB
Hi Friends,
Can anybody help me to create multi-threaded component using Visual Basic 6.0.
Is there any method to access the QueryInterface from VB.
Please send to me with this address ramaniranjann@yahoo.com

Handling Free-threaded Callbacks In VB
I have a free-threaded component, written in C++, which waits on RS232 I/O and does a callback when reading or writing data.

In VB, I have created a Class Module with "Implements xxxLib.Icallback". This callback works successfully when working with local or global data; so, for example, you can store received data in an array. BUT VB crashes when trying to write to a CONTROL on a form.

In the Win32 API, you would be using PostMessage to send the data across thread boundaries when your callback was received. In VB, I assume that VB is treating the controls as ActiveX objects and it doesn't like talking to an apartment-threaded ActiveX object while in a callback from a free-threaded component. But this doesn't solve my problem...

At the moment, I have the truly dreadful "solution" of saving callback data in an array and polling with a timer in my main form. There must be a better way, surely....

Is Winsock Asynchrounous Multi Threaded By Default?
Hi

I read a post by a VB guru in some forum which says that Winsock control in VB 6 is an asynchrounous multi-threaded control by default.
Is it true!???
I don't know how to check if this statement is true or not so if you could please tell me about it then I would be grateful.

Multi-threaded Chat Server In VB 6 Using Winsock
I would like to have your opinion guys about the following situation.
I m trying to develope a messenger like Yahoo/MSN in VB 6 using Winsock. I am thinking about how the server should be made so
that it can cater to many users simultaneously.

Procedure will be as follows:

(a) A client requests login by sending userid and password to the server.
(b) The server checks it in the database and send the result TRUE or FALSE. TRUE means login correct and FALSE means login
incorrect.
(c) After receiving TRUE from server the client sends a message to the server asking to send the contact list.
(d) The server picks contact list from the database and sends it to the client.
(e) Client A sends a message to Client B which arrives at the server.
(f) The server then sends this message to Client B.

There could be many other features like adding a buddy in contact list, deleting him, blocking him e.t.c which I have ignored.

Now the techniques that I may use in developing the server are:


Technique 1
-----------------------

(1) I put a winsock control on a form listening on port 5000.
(2) This single winsock control will be used to login, sending message, loading contact list.
(3) The index property of this control would be 0.
(4) Every time a new connection requests arrive I load a new winsock control increasing the index by 1. For example


Code:
Private Sub serverSocket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngConnectionNumber = lngConnectionNumber + 1

Load serverSocket(lngConnectionNumber)
serverSocket(lngConnectionNumber).LocalPort = 0
serverSocket(lngConnectionNumber).Accept requestID
End If
End Sub
(5) There will be seperate subroutines/functions for login, sending message and loading contact list.


Advantages of technique 1
------------------------------------------
(1) Easy to program.


Disadvantages of technique 1
----------------------------------------------
(1) I don't think it is a multi-threaded server or is it!?
(2) If a client request comes for login and the server is busy then if at the same time another requests comes from some other client to send a message then he will have to wait because server is busy with the login process.


Technique 2
-----------------------

(1) I put 3 different winsock controls on a single form.
(2) All the 3 controls will listen on 3 different ports which are 5000, 5001 and 5002 respectively.
(3) Each winsock control will be used for login, sending message and loading contacts respectively.
(4) The index property of each control will be 0.
(5) Every time a new connection requests arrive I load a new winsock control increasing the index by 1. For example


Code:
Private Sub LoginServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngLoginNumber = lngLoginNumber + 1

Load LoginServer(lngLoginNumber)
LoginServer(lngLoginNumber).LocalPort = 0
LoginServer(lngLoginNumber).Accept requestID
End If
End Sub

Private Sub MessageServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngMessageNumber = lngMessageNumber + 1

Load MessageServer(lngMessageNumber)
MessageServer(lngMessageNumber).LocalPort = 0
MessageServer(lngMessageNumber).Accept requestID
End If
End Sub

Private Sub ContactServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngContactNumber = lngContactNumber + 1

Load ContactServer(lngContactNumber)
ContactServer(lngContactNumber).LocalPort = 0
ContactServer(lngContactNumber).Accept requestID
End If
End Sub
(6) There will be seperate subroutines/functions for login, sending message and loading contact list. (and there are separete winsock controls also for these tasks remember).


Advantages of technique 2
------------------------------------------
(1) It may act like a multi threaded server.
Although here unlike technique 1 there are 3 different winsock controls for 3 different tasks even then I think the client will have to wait in case of two requests at the same time. Because even though controls are 3, the form is single so once loginserver is busy authenticating a client if another client sends a message he will have to wait because control cannot be transfered to SendMessage function as server is already busy in Login. What do you guys say!?


Disadvantages of technique 2
----------------------------------------------
(1) A little difficult to program.



Technique 3
--------------------

(1) I put 3 different winsock controls on 3 different forms. (each control on each form)
(2) All the 3 controls will listen on 3 different ports which are 5000, 5001 and 5002 respectively.
(3) Each winsock control will be used for login, sending message and loading contacts respectively.
(4) The index property of each control will be 0.
(5) Every time a new connection requests arrive I load a new winsock control increasing the index by 1 same as technique 2.
(6) There will be seperate subroutines/functions for login, sending message and loading contact list. (and there are separete winsock controls also on 3 separate form remember).


Advantages of technique 3
------------------------------------------
(1) It may be truly a multi-threaded server. (not sure)
Because now there are three separate controls on three separate forms. So if a client send request for Login and another
client sends a message then the server will not remain busy with Login as it is on different form with different control. In this way both Login and SendingMessage will work simulatneously.


Disadvantages of technique 3
---------------------------------------------
(1) Very difficult to program.
(2) I don't think it is logicalyl correct to use this technique or is it!? The server should be one which will have mulitple threads instead of using three different servers (winsock controls). Isn't it!?


Please give me your comments on the techniques above. As I said earlier my goal is to make a multi-threaded server so if you
think that none of the above is a multi-threaded server and you have a better idea then please tell me.

Is Winsock Asynchrounous Multi Threaded By Default?
Hi

I read a post by a VB guru in some forum which says that Winsock control in VB 6 is an asynchrounous multi-threaded control by default.
Is it true!???
I don't know how to check if this statement is true or not so if you could please tell me about it then I would be grateful.

Multi-threaded Chat Server In VB Using Winsock
I would like to have your opinion guys about the following situation.
I m trying to develope a messenger like Yahoo/MSN in VB 6 using Winsock. I am thinking about how the server should be made so
that it can cater to many users simultaneously.

Procedure will be as follows:

(a) A client requests login by sending userid and password to the server.
(b) The server checks it in the database and send the result TRUE or FALSE. TRUE means login correct and FALSE means login
incorrect.
(c) After receiving TRUE from server the client sends a message to the server asking to send the contact list.
(d) The server picks contact list from the database and sends it to the client.
(e) Client A sends a message to Client B which arrives at the server.
(f) The server then sends this message to Client B.

There could be many other features like adding a buddy in contact list, deleting him, blocking him e.t.c which I have ignored.

Now the techniques that I may use in developing the server are:


Technique 1
-----------------------

(1) I put a winsock control on a form listening on port 5000.
(2) This single winsock control will be used to login, sending message, loading contact list.
(3) The index property of this control would be 0.
(4) Every time a new connection requests arrive I load a new winsock control increasing the index by 1. For example


Code:
Private Sub serverSocket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngConnectionNumber = lngConnectionNumber + 1

Load serverSocket(lngConnectionNumber)
serverSocket(lngConnectionNumber).LocalPort = 0
serverSocket(lngConnectionNumber).Accept requestID
End If
End Sub


(5) There will be seperate subroutines/functions for login, sending message and loading contact list.


Advantages of technique 1
------------------------------------------
(1) Easy to program.


Disadvantages of technique 1
----------------------------------------------
(1) I don't think it is a multi-threaded server or is it!?
(2) If a client request comes for login and the server is busy then if at the same time another requests comes from some other client to send a message then he will have to wait because server is busy with the login process.


Technique 2
-----------------------

(1) I put 3 different winsock controls on a single form.
(2) All the 3 controls will listen on 3 different ports which are 5000, 5001 and 5002 respectively.
(3) Each winsock control will be used for login, sending message and loading contacts respectively.
(4) The index property of each control will be 0.
(5) Every time a new connection requests arrive I load a new winsock control increasing the index by 1. For example


Code:
Private Sub LoginServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngLoginNumber = lngLoginNumber + 1

Load LoginServer(lngLoginNumber)
LoginServer(lngLoginNumber).LocalPort = 0
LoginServer(lngLoginNumber).Accept requestID
End If
End Sub

Private Sub MessageServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngMessageNumber = lngMessageNumber + 1

Load MessageServer(lngMessageNumber)
MessageServer(lngMessageNumber).LocalPort = 0
MessageServer(lngMessageNumber).Accept requestID
End If
End Sub

Private Sub ContactServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
lngContactNumber = lngContactNumber + 1

Load ContactServer(lngContactNumber)
ContactServer(lngContactNumber).LocalPort = 0
ContactServer(lngContactNumber).Accept requestID
End If
End Sub


(6) There will be seperate subroutines/functions for login, sending message and loading contact list. (and there are separete winsock controls also for these tasks remember).


Advantages of technique 2
------------------------------------------
(1) It may act like a multi threaded server.
Although here unlike technique 1 there are 3 different winsock controls for 3 different tasks even then I think the client will have to wait in case of two requests at the same time. Because even though controls are 3, the form is single so once loginserver is busy authenticating a client if another client sends a message he will have to wait because control cannot be transfered to SendMessage function as server is already busy in Login. What do you guys say!?


Disadvantages of technique 2
----------------------------------------------
(1) A little difficult to program.



Technique 3
--------------------

(1) I put 3 different winsock controls on 3 different forms. (each control on each form)
(2) All the 3 controls will listen on 3 different ports which are 5000, 5001 and 5002 respectively.
(3) Each winsock control will be used for login, sending message and loading contacts respectively.
(4) The index property of each control will be 0.
(5) Every time a new connection requests arrive I load a new winsock control increasing the index by 1 same as technique 2.
(6) There will be seperate subroutines/functions for login, sending message and loading contact list. (and there are separete winsock controls also on 3 separate form remember).


Advantages of technique 3
------------------------------------------
(1) It may be truly a multi-threaded server. (not sure)
Because now there are three separate controls on three separate forms. So if a client send request for Login and another
client sends a message then the server will not remain busy with Login as it is on different form with different control. In this way both Login and SendingMessage will work simulatneously.


Disadvantages of technique 3
---------------------------------------------
(1) Very difficult to program.
(2) I don't think it is logicalyl correct to use this technique or is it!? The server should be one which will have mulitple threads instead of using three different servers (winsock controls). Isn't it!?


Please give me your comments on the techniques above. As I said earlier my goal is to make a multi-threaded server so if you
think that none of the above is a multi-threaded server and you have a better idea then please tell me.

Creating A Queue Buffer In A Multi Threaded EXE
Hi ALL

Just found this little part of the world while desperatly looking for help!.

Im converting an old VB app of mine that Reads a Serial port, and then Sends events to mulitple clients via IP. ( It has a configeration Server as well as an Event server, runs as an NT service etc etc)

In the new version I want to improve the Threading and have actual Que buffers for the messages. ( Make it more scalable)

An example of the config service. Written in a single activeX exe

1 Thread runs the IP server that handles outputing the responces. It checks the "Eventstosend" Buffer every X millisecounds. It also recieves requests and places these straight into the "Tobeproccessed" Buffer.

1 Thread Runs the Requests to be processed, and It checks the "ToBeProccessed" buffer every X millsecounds. It then handles the request and places the responce in the "EventstoSend" Buffer.


All seemed fairly easy, or so I thought. I have all the componenent finished and working fine in the development enviroment, but of course everything is in the same thread. When compiled, and all runing in there own threads each, well It dont work!.

I initially had the Message Queses in a Module and used Mutexs to control them so only 1 thread could work on a buffer at a time, the mutexs worked a treat, however I did not relaise that each thread has its Own copy of the common variables, therefore when 1 updated the common variables the other doesnt see it.

I have played around with creating a class and having only 1 instance of this and trying to have both threads use it, but it didnt work.. Basically I have got to the "Oh **** Im really stuck " stage..

I have looked at MSMQ, and it seems too big for what I want. ( Dont want to install SQL, and cant gaurentee that the Server will be NT Server ( IE not workstation).

Can anyone suggest a way to do this?. ( Oh and in the mean time I'm using a File to write and read from.. ack, but it means I can start to debug continu on the rest of the code)

Im thinking maybe an externall DLL , but I'm starting to get a wee bit confused with how this will differ from my current situation..

TIA

Rob dB

Ms Word Object Printing Speed? Multi-threaded?
I am using MS Word Object automation to print letters. The syntax is like:

Set wdApp = CreateObject("word.application")wdApp.Documents.Open (pathmyfile.doc)
wdApp.Visible = False

'a lot of text modification are applied here

wdApp.PrintOut False
DoEvents
wdApp.ActiveDocument.Close wdDoNotSaveChanges
wdApp.Application.Quit wdDoNotSaveChanges
Set wdApp = Nothing

There is a button on the window to trigger above code. The problem is that it takes too much time to open a Word application, load a file and print. I am wonder what is the best way to speed up printing? The ideal solution is for the program to fire a printing msg to some kind of object(???) and continue to serve the user. This client/server program is for &lt;10 users, so simpler is better.

Any suggestion is appreciated.

Single To String To Array To Single
Hi,

I have a sub in my app that requires 2 parameters - both of the type Single. These parameters are combined in a string, seperated by ":". Then this string is passed to another computer. There I want to split it into an array.
I have this code, but it gives an error:


VB Code:
Dim place() As Single'Incoming is a string place = Split(Incoming, ":")


It gives a type mismatch. What can I do about it?

tnx.

How To Single Exe In Single Machine
hello friends

i want that my exe should run in single machine and if accessed by another machine it shouldn't be opned. what should i do.

please help me out

What Is The Difference Between Multi-threaded And Multi-processing
What is the difference between multi-threaded and multi-processing interms of software. If you can prove examples that would be fine. Also which is more stable when it comes to socket programming

App With A Single Run
Hi All,

If i start up my exe it runs...if i double another time the exe..it start another up..

Is there something that detects if the exe already started up?

I want my exe only run one time at the time..

well hope someone can give me some information..

thankz in advance,

greetz,
Alex

Single Exe?
Is there anyway to compile a single exe file with everything it needs to run? I'm not talking about a setup program, but a way to compile a program to run with nothing else.....just itself.

Single
Why am I losing decimal points? The last example came out fine.

Code:
Dim sngTest As Single
sngTest = 29876543.15
Debug.Print sngTest
sngTest = 2987654.15
Debug.Print sngTest
sngTest = 298764.15
Debug.Print sngTest
sngTest = 29876.15
Debug.Print sngTest

'Result
2.987654E+07
2987654
298764.2
29876.15

Run Single EXE On The LAN
Hi,

I have an vb6 application which is deploy on 30 user pcs, I would like to change on create a shortcut for all the users point to one EXE file and run off the LAN drive.

The applications is doing some DDE function and API calls, Is that OK to just let everyone run on the single EXE file. Then I only need to update one EXE file whenever the program code changed instead of updates from PC to PC.

Thanks!

Single EXE In Vb6
Hi,

Is that an advantage to put the single EXE file that generate by the vb6 on the LAN and let multi-user just point a shortcut to and all running the application from that single EXE copy?

Thanks!

SQL On Single PC
<HTML><DIV class=bgcolor STYLE="background-color: ;"><P>I don't
have server facility, how I can use SQL databse facility on a
single PC.</P>
<P>Please reply.</P>
<P>Regards,</P>
<P>Asif </P></DIV></HTML>
<DIV>

Single Install
Hi - I want to distribute my VB6 program on the internet and an intranet. I've tried VB's wizard and it creats 3 (setup.exe, setup.lis and xyx.cab) files. My program includes data files and ocxs. I've tried Inno, but am looking for an easy was to creat a single installation file. Any suggestions? Thanks.

Single BLT Buffer
Is there a way to use a single BLT buffer and gettin rid of screen fliquer so you don't have to a .flip a temporary or secondary on the primary, it goes ALLOT faster when u blt directly to the primary alltought it fliquer, but my FPS jumped from 60 FPS to 300FPS. So can you remove the fliquering without using a secondary blt buffer? or is just a way faster then fliping a secondary/temporay buffer into the primary?

Copyright 2005-08 www.BigResource.com, All rights reserved