Results 1 to 6 of 6

Thread: [RESOLVED] Exiting in C#

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    50

    Resolved [RESOLVED] Exiting in C#

    Okay, a pitifal question, but how do I exit my program when it's running? Same as the ext button on the Windows API does, but I have a menu item that I want to close the program.

    I know in VB it's just "End", what is it in C#?

    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Exiting in C#

    It definitely SHOULDN'T be End in VB. Using End is a terrible way to exit an app because it simply halts execution immediately with no cleanup whatsoever. In both VB.NET and C#, as well as any other .NET language, you can simply call Me.Close if the form is the startup form. Otherwise you should call Application.Exit.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Exiting in C#

    There is no "End" in VB.NET, only in VB 6. Both VB.NET and C# use like what John posted.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    50

    Re: Exiting in C#

    Thanks guys, I have one problem, when I do the Me.Close or Application.Exit commands I get this error:

    Code:
    Only assignment, call, increment, decrement, and new object expressions can be used as a statement

  5. #5
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Re: Exiting in C#

    yer you have to type this: application.exit();

    you need the two brackets after exit

    :-)

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    50

    Re: Exiting in C#

    Ah yes, that got it, thanks. .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width