?
Solved

which VS2010 template?

Posted on 2011-03-06
16
Medium Priority
?
625 Views
Last Modified: 2012-08-14
I want to create an executable that sends emails every night. I cant use the web templates.
From windows templates, which templates should I use? Console app?? windows service??
0
Comment
Question by:Camillia
[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
  • 9
  • 6
16 Comments
 
LVL 4

Expert Comment

by:cauos
ID: 35048395
they all can do the same jobs, but using windows service give you advantage of handling it using windows itself like any other services, also you don't need to remember every time to start it when for example restart the server.
if you want to send  email using some data from sql server, it's good to add job to send emails. check this link to setup database mail on sql server 2005
http://www.databasejournal.com/features/mssql/article.php/3626056/Database-Mail-in-SQL-Server-2005.htm
0
 
LVL 7

Author Comment

by:Camillia
ID: 35049081
thanks, this is sql 2000 unfortuantely. I'll use windows service template. thanks.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 35049521
even if the application is not built to be interactive, I really prefer to build one that has a UI just in case you need to debug it. You can then handle parameters to detect runs in batch or interactively.

check http://www.emoreau.com/Entries/Articles/2008/11/Passing-arguments-to-an-application-startup.aspx
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Author Comment

by:Camillia
ID: 35050292
eric, so I should use which template? I looked at your link but not clear.. This app is a small app. Reads 5 rows of data and emails it to some managers, every night at 9 PM.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35050473
I prefer to build a "Windows Forms application"
0
 
LVL 7

Author Comment

by:Camillia
ID: 35050533
oh and then i can schedule the windows form? does that link show it how to??
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35054919
I schedule some of these applications passing an argument like /batch so the job starts, does its job, and quits automatically.
0
 
LVL 7

Author Comment

by:Camillia
ID: 35060777
I implemented this in C#. How do I call it in "batch" mode. I went to "properties", "debug" and typed "/batch". I step thru the code and the enum "enuEnvironment" comes out as unknown and the form pops up.

I also tried "/bath//ENV_DEV" but still comes out as unknown and the form interface pops up.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35060862
check http://msdn.microsoft.com/en-us/library/cb20e19t(v=vs.80).aspx to find out how to handle C# command line arguments
0
 
LVL 7

Author Comment

by:Camillia
ID: 35060897
I tried "/BATCH"..upper case. Now else if (GlobalArguments.BatchMode) comes out as false.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35060956
can you show your code?
0
 
LVL 7

Author Comment

by:Camillia
ID: 35061096
yes, i just tried your VB.Net code with /BATCH and that worked. This is my C#  code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WallboardEmail
{
    public static class ModMain
    {
        public static  GlobalArgumentsStructure GlobalArguments = new GlobalArgumentsStructure();


        public static void Main(string[] pArgs) //pass argument from command line by using the parameter
        {
            GetCommandLineArgs(pArgs);
            
            StartApplication();
        }

        #region methods
        private static void StartApplication()
        {
            if (GlobalArguments.DisplayArgs)
            {
                //do something here
                Application.Exit();

            }
            else if (GlobalArguments.BatchMode)
            {
                //Launch a process that has no UI
                //send email //same cProcess in orig code
                Log.LogTrace("This line was added by a batch process. Email Sent");

            }
            else
            {
                //Launch the UI
                Form1 form = new Form1();
                Application.Run(form);
            }

        }

        private static void GetCommandLineArgs(string[] pArgs)
        {
            //If no arguments are passed to the application, short-circuit the process
            if ((pArgs.Length == 0))
            {
                GlobalArguments.DisplayArgs = true;
            }

            //Ensure all arguments are in upper case
            for (Int32 intI = 0; intI <= pArgs.Length - 1; intI++)
            {
                pArgs[intI] = pArgs[intI].ToUpper();
            }

            //Search for expected arguments (all others being ignored)
            var _with1 = GlobalArguments;
            _with1.DisplayArgs = (Array.IndexOf(pArgs, "/?") >= 0);
            _with1.BatchMode = (Array.IndexOf(pArgs, "/BATCH") >= 0);

            if (Array.IndexOf(pArgs, "/ENV_DEV") >= 0)
            {
                _with1.Environment = GlobalArgumentsStructure.enuEnvironment.Dev;
            }
           
            else if (Array.IndexOf(pArgs, "/ENV_PRODUCTION") >= 0)
            {
                _with1.Environment = GlobalArgumentsStructure.enuEnvironment.Production;
            }
            else
            {
                _with1.Environment = GlobalArgumentsStructure.enuEnvironment.Dev;
            }

        }
        #endregion

        #region enum
        public struct GlobalArgumentsStructure
        {
            public enum enuEnvironment
            {
                Unknown = 0,
                Dev = 1,
                Production = 3
            }

            public bool BatchMode;
            public enuEnvironment Environment;

            public bool DisplayArgs;
        }


        #endregion
    }
  
}

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35061393
is your Main method ever called?
0
 
LVL 7

Author Comment

by:Camillia
ID: 35061571
yes, i step thru it.

Calls GetCommandLineArgs., this line is true:
_with1.BatchMode = (Array.IndexOf(pArgs, "/BATCH") >= 0);

Then calls StartApplication and
1.  if (GlobalArguments.DisplayArgs) is false
2. This also is false but in your VB code, it's trueelse if (GlobalArguments.BatchMode) //comes out as false
0
 
LVL 7

Author Comment

by:Camillia
ID: 35061657
it's not because of this line, is it?

public static  GlobalArgumentsStructure GlobalArguments = new GlobalArgumentsStructure();

i dont think so but not sure why GlobalArguments.BatchMode becomes false in "StartApplication" routine...
0
 
LVL 7

Author Comment

by:Camillia
ID: 35061819
Fixed it. I added this line of code:

_with1.BatchMode = (Array.IndexOf(pArgs, "/BATCH") >= 0);
            GlobalArguments.BatchMode = (Array.IndexOf(pArgs, "/BATCH") >= 0);

GlobalArguments.BatchMode wasnt set. Not sure how your VB code works. You dont have that line of code and still works. But at least, this gets me going.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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