Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoEvents

Status
Not open for further replies.

AGIMA

Programmer
Jul 24, 2003
95
AU
OK, I have this little problem. I am writing a VB.Net COM to retrieve email from a mail server. Every thing work fine except when the main application (Using the new COM) askes for some information from the mail server.

Here is the situation:

Main application calls a function in the Email COM.
The Email COM asks the mail server.
The Email COM then has to wait for a response before the function can exit. I have a thread that waits for this reponse and populates a variable with the returned data.
The main function has to detect this imcoming data and responsed.

Now here the problem. How can I get the function to wait around and give the background thread a chance to accept the incoming data. In VB6 I would noramlly use a DoEvents in a while loop but this process is no longer valid.




Public Function GetMessagesList() As cMailList

'Sends the request to the mail server
Me.SendString("list")


'Now has to wait for the response from the mail
'server so it can process the returned string
'and put it in the custom cMailList object.
While Not aMailResponse.EndsWith("." & vbCrLf)
'This is where I need the function to give the
'background thread time to retrieve the incoming data
DoEvents

End While

End Function

Some idea about this would be helpful. Remember this is a COM so I cant use the application.doevents or form.doevents.

AGIMA where professional web hosting is our business.

AGIMA Computing
 
Ok I found the solution to my little problem.

First I start a new thread that contains the routine that I want to run, and within this routing it populates a variable.

After I have called for the thread to start I then call the .Join method on the thread. The application stops and waits for the thread to finish before it continues on.

If anyone has a better way to do this I would love to know as this way seems a bit dodgy.

aRecieveThread = New Thread(AddressOf DataRead)
aRecieveThread.Name = "Data Receiver"
aRecieveThread.Start()
aRecieveThread.Join()



AGIMA - professional web hosting is our business.

AGIMA Computing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top