dcsimg
Results 1 to 9 of 9
  1. #1

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,048

    Opinions on Code Effeciency

    I am sure it probably isn't entirely effecient, but what I am trying to do is create a seperate program to update the main program, which will be shipped with the main program, but compiled as update.exe instead of being part of the main program's .EXE

    Anyways getting to it more, I had a question a while back about formless applications and found a simple solution, but was wondering if its the only way, or is there something better, currently I have the Form opacity set to 1%, Borderless, Hidden from Taskbar. It is set as the start-up form so when it is launched practically everything is done in the background, it has a system-Tray icon to let users know its running and checking for updates, once it checks over a certain period of time it automatically closes until the events trigger it to open and check again.

    Someone had a formless application example before, but it seemed that it was overly complicated for what I was needing - I am just curious if this is good enough to do or if this is one of those "Easy - but not so good" ways.

    Thanks
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  2. #2
    PowerPoster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,091

    Re: Opinions on Code Effeciency

    I'm wondering if you could use a console app instead of a form app?
    Please remember next time...elections matter!

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Opinions on Code Effeciency

    Yeah... a console app's a little more appropriate for "a tool that shouldn't show a form".

    But you also don't need to resort to tricks like 1% opacity forms to make a formless application. The real trick is telling VB to use a Sub Main() to start so you can hijack the bootstrapping code and tell it to start a message loop without tying it to a form. VB hides all that away from you and lately even I have trouble figuring out how to do it. That's why I like good old C#, it puts stuff where I can see it yet it's still out of the way.

    Anyway, if the updater's relatively quick, I feel like the hoops you have to jump through to get a formless app with a notification icon is just... too much work. From Windows Vista onwards, the odds the user will even see a notification area icon are slim: most are hidden by default because people got tired of half their taskbar being devoted to little more than advertisements for programs they'd already bought.

    So why not go for a console application they can minimize if annoyed?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,606

    Re: Opinions on Code Effeciency

    Use a windows form app... turn on Application Framework... or is it turn it off? ... what ever it is, do the other... remove the form from the project, add a module, create a public Sub New... put your code there or, at least your entry code there... then in the project properties, set the startup object to Sub New... That essntially gets you a formless app w/o too much mucky muck. And if you still need to show a form, you still can.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,606

    Re: Opinions on Code Effeciency

    Quote Originally Posted by Sitten Spynne View Post
    Yeah... a console app's a little more appropriate for "a tool that shouldn't show a form".

    But you also don't need to resort to tricks like 1% opacity forms to make a formless application. The real trick is telling VB to use a Sub Main() to start so you can hijack the bootstrapping code and tell it to start a message loop without tying it to a form. VB hides all that away from you and lately even I have trouble figuring out how to do it. That's why I like good old C#, it puts stuff where I can see it yet it's still out of the way.

    Anyway, if the updater's relatively quick, I feel like the hoops you have to jump through to get a formless app with a notification icon is just... too much work. From Windows Vista onwards, the odds the user will even see a notification area icon are slim: most are hidden by default because people got tired of half their taskbar being devoted to little more than advertisements for programs they'd already bought.

    So why not go for a console application they can minimize if annoyed?
    My objection to console apps like this is they have a tendency to create a console window that does... what? nothing? can't be interacted with either... just as bad as a transparent form that does nothing... it's easier to flip the application framework setting, create a sub New, and set that as the startup object...

    Then if you still need to show a form, for options, or notification, or what ever... it's there.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Opinions on Code Effeciency

    It doesn't "do nothing" if you do something with it.

    OP mentioned using a notification tray icon to let the user know it's running, so even a simple, "Updating whatever, please wait..." seems sufficient. Seems like the only reason there's a Form involved is that's the most intuitive way to get a notification tray icon.

    And it's not a "sub new" you're looking for. The entry point is a static method named "Main", the VB idiom being a Module with a Sub Main(). That's only step 1 if you want to show forms, you really have to set up an application context as well, and I'm trying to figure out if it's worth writing a tiny tutorial or if the Console Application can do all OP wants.
    Last edited by Sitten Spynne; Jan 25th, 2018 at 02:33 PM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  7. #7

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,048

    Re: Opinions on Code Effeciency

    I forgot to disclaim about that I want to keep the form concept available due to the ability to access settings, because the user will have the ability to change the intervals it checks for the updates if they only want it to check once then quit great! Otherwise it will continue checking for lets say 24 hours then quietly close.

    The concept I was trying to do here is something many other apps do like chrome where they do processes in the background (some of which are stupid), Another application I use is Discord and it does the very same thing with the tray icon (its only there as a reminder its running and not to disturb)

    Another question, is how to automatically click through the run with Internet explorer, that is what I use to update currently because I use github and there is really no good way to update using github, so improvising is what I had to do so, basically I check if the path exists then just download the new setup file (its a MSI) I just navigate the URL, and then the dialog prompts the user to run, save, or cancel, I simply want to bypass that dialog, (NOT the one where it asks if you want to actually install I just want to run the installation wizard automatically) - The only reason I am using IE is because everything else has resulted in some sort of file exception error and so forth so this was the only clear path that worked fyi if anyone wanted to know why I use the internet explorer method and not just the "normal" way with a web request.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  8. #8

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,048

    Re: Opinions on Code Effeciency

    I am not interested in using a console application because of *how* it is done (as explained in this latest reply above) I have specific things I am doing, basically just porting from where they check for updates to a seperate .exe that runs automatically to check updates.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  9. #9
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,025

    Re: Opinions on Code Effeciency

    Maybe you could adapt Johns example.

    Recently, I replied to a thread on another forum where the poster asked how to create an application that displayed an icon in the notification area (aka system tray) but didn't require a form to be created and hidden. My first thought was that a form was required but, upon reflection, I thought that there must be another way. I recalled having read something about the ApplicationContext class so I investigated that further and that is indeed the way to do it.

    Generally, whether you create your own Main method or you use the VB application framework (which hides the main method from you, but it's there) you call Application.Run and pass a form as an argument, which becomes the application's main form. You can also pass an object whose type inherits ApplicationContext as an argument to Application.Run. The application will then close when you call Application.Exit or Application.ExitThread.

    The example attached below meets the requirements of the poster of the aforementioned thread. They wanted a NotifyIcon and the ability to use an OpenFileDialog. For that, I created a component that provided a designer, which made it easy to configure the NotifyIcon and the ContextMenuStrip. My derived ApplicationContext then creates an instance of that component and duly disposes it when the ApplicationContext itself is disposed.

    Simply run the app and you will see the NotifyIcon. Right-click the icon to get a menu that provides items to display an OpenFileDialog and to exit the app.

    Finally, note that the attached application was written in VB 2010, so you will need VS 2010 or VB Express 2010 to open it.



    http://www.vbforums.com/showthread.p...ay-Application

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width