473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Posting an event

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
Nov 20 '05 #1
7 1487
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/library/de...ingExample.asp

http://msdn.microsoft.com/msdnmag/is...t/default.aspx

http://msdn.microsoft.com/library/de...enersample.asp

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" <je*********@hsi.com> wrote in message
news:5B**********************************@microsof t.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

Nov 20 '05 #2
Thanks Trev for your quick reply!

I'm just trying to make a distinction between the Windows API options to POST vs. SEND a Windows event. I'd really rather avoid trying to start a new thread. I want the work to occur on this thread, just AFTER the application returns to the Windows message handler and after Windows processes anything else that entered the message queue before my POST. So, for example, if I put a "MsgBox" in my form's load event, the message box displays, then when I press OK the form displays. But what if I want the message box to display immediately after my form displays

Is this not a valid technique with VB

Thanks - Jeff
Nov 20 '05 #3
> But what if I want the message box to display immediately after my form
displays?

You could use the Activate event instead of the load event although you
would have to distinguish between the first time it is shown and times when
it is simply activated.

A better method would be to do the processing after you call Form.Show
(maybe with a call to DoEvents). E.g.

-------------------

Dim obJForm as new MyForm

objForm.Show
Application.DoEvents()
Messagebox.Show(........)

-------------------
If you could provide an explanation of what you're trying to accomplish, I
may be of more help. Also, try posting in the
microsoft.dotnet.framework.windowsforms group as this may be more
appropiate.

HTH,

Trev.
"Jeff Casbeer" <je*********@hsi.com> wrote in message
news:00**********************************@microsof t.com...
Thanks Trev for your quick reply!

I'm just trying to make a distinction between the Windows API options to POST vs. SEND a Windows event. I'd really rather avoid trying to start a
new thread. I want the work to occur on this thread, just AFTER the
application returns to the Windows message handler and after Windows
processes anything else that entered the message queue before my POST. So,
for example, if I put a "MsgBox" in my form's load event, the message box
displays, then when I press OK the form displays. But what if I want the
message box to display immediately after my form displays?
Is this not a valid technique with VB?

Thanks - Jeff

Nov 20 '05 #4
Thanks again for responding Trev. My background is with Powerbuilder, but I've done this in other languages as well. We load the window before beginning the slower process of retrieving data, or the non-visual processes of creating business objects, etc. In other words, anything that isn't related to the user interface directly gets deferred until the form has completed drawing. We do this with a custom windows event. We set up a custom event on the form and then "post" the event. Posting the event tells Windows to stick the event at the bottom of the message queue rather than the top. (Raiseevent seems to use window's "send" functionality, which runs the event *right now*.) The effect is that the form displays first, faster, before all other processing occurs, resulting in better perceived performance

VB coders don't use this sort of technique

Thanks - Jeff
Nov 20 '05 #5
is a more common way to do that not

1. show splash screen
2. do "business" stuff
3. load "real" form
?
....

but for your idea you can maybe create a thread in formLoad event?
Dominique
"Jeff Casbeer" <je*********@hsi.com> wrote in message
news:68**********************************@microsof t.com...
Thanks again for responding Trev. My background is with Powerbuilder, but I've done this in other languages as well. We load the window before
beginning the slower process of retrieving data, or the non-visual processes
of creating business objects, etc. In other words, anything that isn't
related to the user interface directly gets deferred until the form has
completed drawing. We do this with a custom windows event. We set up a
custom event on the form and then "post" the event. Posting the event tells
Windows to stick the event at the bottom of the message queue rather than
the top. (Raiseevent seems to use window's "send" functionality, which runs
the event *right now*.) The effect is that the form displays first, faster,
before all other processing occurs, resulting in better perceived
performance.
VB coders don't use this sort of technique?

Thanks - Jeff

Nov 20 '05 #6
Jeff,

There are many ways to accomplish this with a form in VB including
threading, asynchronous delegates and DoEvents() (note that these techniques
should apply to all dotnet languages, not just VB). The difference is that
windows forms in dotnet add a layer to insulate the developer from having to
deal with the low-down windows events (although you can still get at them
with the WndProc method or API calls).

Events in .NET have nothing to do with the windows message queue events,
instead their implementation is based on multicast delegates (synchronous
ones) and are a managed part of the dotnet framework. Because these
delegates are synchronous, there is no messsage queue for them and you can't
post a message to the bottom of the queue.

If you want your form to be shown fully before populating the loading of the
data, then try the following:

-------------------------------

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
' Call the Base Method
MyBase.OnLoad(e)

' Allow the window to process all its waiting windows messages
Application.DoEvents()

' Do stuff to load the data

End Sub

--------------------------------

Note that with the above example, your form should paint OK with the call to
DoEvents, but it will still not respond to user messages while loading the
data (unless you call doevents while loading the data, or use a thread to
load the data).

If you are loading a lot of data, then I would suggest using a thread.
They're not that hard to do in .net as long as you are careful when calling
a method on the form or one of its controls.
Hope this helps,

Trev.

"Jeff Casbeer" <je*********@hsi.com> wrote in message
news:68**********************************@microsof t.com...
Thanks again for responding Trev. My background is with Powerbuilder, but I've done this in other languages as well. We load the window before
beginning the slower process of retrieving data, or the non-visual processes
of creating business objects, etc. In other words, anything that isn't
related to the user interface directly gets deferred until the form has
completed drawing. We do this with a custom windows event. We set up a
custom event on the form and then "post" the event. Posting the event tells
Windows to stick the event at the bottom of the message queue rather than
the top. (Raiseevent seems to use window's "send" functionality, which runs
the event *right now*.) The effect is that the form displays first, faster,
before all other processing occurs, resulting in better perceived
performance.
VB coders don't use this sort of technique?

Thanks - Jeff

Nov 20 '05 #7
Thanks to Dominique and Trev for the response. From what I can see from reading about calling the API and Control.WndProc and the related stuff, fooling with the Windows API isn't invited by .NET. *UNMANAGED* is a word that kept showing up, and the help information doesn't make it sound pretty

I'm going to work on using a new thread next, and see if that takes me where I want to go... (oh no, cover your eyes...) today

Thanks again guys - Jeff
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roger Walter | last post by:
I have a .Net web page that is posting twice after the submit button is clicked once. How can that happen? I have turned tracing on and it writes two records to the trace log and posts twice. ...
3
by: Itai | last post by:
I have an aspx file named index.aspx which contains two ‘form' sections, one that has the runat=server attribute (e.g From1) and one which is a regular HTML form (e.g SignInForm). I am trying...
9
by: Mike | last post by:
How do I prevent SQL Server 2000 from posting successful backup completion messages to the Windows 2000 Application Event Log? I have scheduled jobs which backup my transaction logs on 50+...
4
by: Newbie | last post by:
Hi, I need help in posting asp .net application web form to another asp based web app. I have seen many examples using HttpWebRequest class but the problem is I do not want the request back...
4
by: Nikhil Patel | last post by:
Hi all, I have a simple page with a dropdown and a datagrid. But the page is not posting back at all when I select an item in the dropdown. What could be wrong? Thanks.
4
by: Jason Penniman | last post by:
Here's an interesting one that has me stumped. I have several ASP.NET applications writen in VB.NET that stopped posting back on click of a button. Nothing has changed in the code or the...
8
by: Pazza | last post by:
Hi, Is there a way to cause the form submit button click event handler to fire when posting to a aspx page using httpwebrequest. In my tests the load event fires but not by button click event....
4
by: Murali Krishna. Siruvuru | last post by:
Hi, All of a sudden, all my Button Controls and Image Button Controls are not posting back data. I have Click event and event handlers in the code. Page itself is not posting back. Whereas...
11
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.