Re: Posting an event
From: Trev Hunter (hunter_trev_at_hotmail.com)
Date: 02/15/04
- Next message: Bernie Yaeger: "F1, keywordindex, and combobox dropdowns"
- Previous message: Corrado Cavalli [MVP]: "Re: MSComm in VB.NET and Stepper Motor Serial Control"
- In reply to: Jeff Casbeer: "Posting an event"
- Next in thread: Jeff Casbeer: "Re: Posting an event"
- Reply: Jeff Casbeer: "Re: Posting an event"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 15 Feb 2004 20:00:21 -0000
Jeff,
If you want to do asynchronous processing, look up the following topics in
the help files and in MSDN
Threading
Thread Pool
Asynchronous delegates
The following links may also be of use:
http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/default.aspx
Be careful with threads and windows forms - always remember the golden
rule - you shouldn't call a method on a form from a different thread - use
Form.Invoke to call it instead.
If you want your application to process windows messages before executing a
piece of code, call System.Windows.Forms.Application.DoEvents(). DoEvents
processes waiting messages before continuing. InVB6 it was used to allow
your window to stay responsive while preforming background processing. In
VB.net, the addition of threading has become the preferred method for
background processing, but DoEvents is still available.
Below is a quick example of how to call a method asynchronously:
-------------------------
' Delegate to call async
Private Delegate Sub DoStuffDelegate(Byval MyParam as String)
' Main Entry point
Private Sub Main()
' Local Variables
Dim DoStuffAsync as new DoStuffDelegate(AddressOf Me.DoStuff)
Dim objResult as IAsyncResult
' Start the async processing
objResult = DoStuffAsync.BeginInvoke("test", nothing, nothing)
' Do some stuff in this thread
Threading.Thread.Sleep(5000)
' Pause until the processing has finished
DoStuffAsync.EndInvoke(objResult)
End Sub
' Method that runs on a different thread
Private Sub DoStuff(Byval Param as String)
' Do stuff on a different thread
Threading.Thread.Sleep(10000)
End Sub
-------------------------
Hope this helps,
Trev.
"Jeff Casbeer" <jeffcasbeer@hsi.com> wrote in message
news:5BD95E99-4B84-4396-B938-11488B35564A@microsoft.com...
> New to VB...
>
> What is the VB syntax for posting a Windows event? For example, to have
an event fire AFTER a form loads, I'd add a posted call to a "post_load"
event, from "load". What is the VB syntax for that deferred call?
Raiseevent seems to be synchronous, as does just calling the handler
subroutine. Also, how do I defer processing to allow windows to process
incomplete events, eg., painting?
>
> Thanks - Jeff
- Next message: Bernie Yaeger: "F1, keywordindex, and combobox dropdowns"
- Previous message: Corrado Cavalli [MVP]: "Re: MSComm in VB.NET and Stepper Motor Serial Control"
- In reply to: Jeff Casbeer: "Posting an event"
- Next in thread: Jeff Casbeer: "Re: Posting an event"
- Reply: Jeff Casbeer: "Re: Posting an event"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|