Solved

how to close windows form in vb.net

Posted on 2014-11-04
7
437 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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 34

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

Industry Leaders: 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!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

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