?
Solved

how to close windows form in vb.net

Posted on 2014-11-04
7
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 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 34

Assisted Solution

by:it_saige
it_saige earned 1000 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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