Solved

how to close windows form in vb.net

Posted on 2014-11-04
7
422 Views
Last Modified: 2014-12-29
Hi

i have the following simple code in my windows form application (vb.net + VS2010)
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         
         

        SendNotification()
 
        Application.DoEvents()
        Application.Exit()
    End Sub

Open in new window


my problem is while the program is executing the function SendNotification() the program will jump to Application.DoEvents() and         Application.Exit() causing the form to be closed while some events are not completed in the function SendNotification()

any suggestion pls?
0
Comment
Question by:Kamal Khaleefa
7 Comments
 
LVL 6

Expert Comment

by:Mandeep Singh
ID: 40423303
Use

FormName.Close()

or

Me.close()
0
 
LVL 16

Author Comment

by:Kamal Khaleefa
ID: 40423332
yes thats correct but my problem as described up i need to close the form after all events are executed successfully
0
 
LVL 11

Expert Comment

by:louisfr
ID: 40423372
It depends on what the SendNotification method does.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40423451
SendNotification is probably an asynchrone method. The code continues without waiting when you call an asynchrone method.

Look at the documentation for the function. There could be a way to call it so that it runs synchronously. There might be an event that you can subscribe to that will trigger when the method has finished. There could be an alternative method that you can call instead, such as the ShowDialog (synchrone) that can be used instead of the Show method (asynchrone) to display a Windows Form.
0
 
LVL 16

Author Comment

by:Kamal Khaleefa
ID: 40423600
@Jacques Bourgeois (James Burger)

you are absolutely correct . this is asynchronous  method used to send push notification for apple /iPhone

 Sub SendNotification()

        Dim push As New PushBroker


        AddHandler push.OnNotificationSent, AddressOf NotificationSent
        AddHandler push.OnChannelException, AddressOf ChannelException
        AddHandler push.OnServiceException, AddressOf ServiceException
        AddHandler push.OnNotificationFailed, AddressOf NotificationFailed
        AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionExpired
        AddHandler push.OnDeviceSubscriptionChanged, AddressOf DeviceSubscriptionChanged
        AddHandler push.OnChannelCreated, AddressOf ChannelCreated
        AddHandler push.OnChannelDestroyed, AddressOf ChannelDestroyed

'some code is done here
end sub

Open in new window


is there a way to close the form and kill the process after i make sure all the code is executed
0
 
LVL 32

Assisted Solution

by:it_saige
it_saige earned 250 total points
ID: 40424147
You need to decide which event(s) signify that your process has completed.  NotificationSent, NotificationFailed and ChannelDestroyed look like good candidates.  So long as you are not sending multiple notifications, then you could easily tell the program to exit when you receive any of those events.

If you are sending multiple notifications, then you need to use some sort of Queue or List to send from, what you could do is also wait until the list is exhausted and signal to close your application using the above events and a boolean value indicating that it is ok to close.

If you are using a Queue, then you will need to specify a boolean value that states whether you are adding additional items to the Queue.  Once this boolean value is false and the queue is exhausted, then you can signal to close your application using the above events and a boolean value indicating that it is ok to close.

-saige-
0
 
LVL 16

Author Closing Comment

by:Kamal Khaleefa
ID: 40521584
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now