Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What is the best way to create background application?

What is the best way to create background application?

Scheduled Pinned Locked Moved C#
questionperformancetutorial
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B bonzaiholding

    If i want to create an application without any console and without any form that for example: 1. every 20 hours send an email 2. backup some folder or doing anything without the user interaction. 3. Will write a log to a file. 4. will run a process if some event occur. I know that i can make a form application but then i need to mark the form with 0% Opacity. That will take a lot of memory for the process. What is the best way?

    S Offline
    S Offline
    Saksida Bojan
    wrote on last edited by
    #2

    write it as service. But why do you need such app. Such app can be easly considered malicious programs

    B 1 Reply Last reply
    0
    • S Saksida Bojan

      write it as service. But why do you need such app. Such app can be easly considered malicious programs

      B Offline
      B Offline
      bonzaiholding
      wrote on last edited by
      #3

      Thanks. I need it to backup files in my system and to sync between some computer in my office.

      S 1 Reply Last reply
      0
      • B bonzaiholding

        Thanks. I need it to backup files in my system and to sync between some computer in my office.

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #4

        Then i suggest writing it so that it will move to system tray

        1 Reply Last reply
        0
        • B bonzaiholding

          If i want to create an application without any console and without any form that for example: 1. every 20 hours send an email 2. backup some folder or doing anything without the user interaction. 3. Will write a log to a file. 4. will run a process if some event occur. I know that i can make a form application but then i need to mark the form with 0% Opacity. That will take a lot of memory for the process. What is the best way?

          B Offline
          B Offline
          Baeltazor
          wrote on last edited by
          #5

          Why not try chucking it in the system tray?

          Regards, Jason Pezzimenti.


          If you liked the answer that I have provided, then please click the 'Good Answer' link on the bottom-right of this post. Thank you.

          1 Reply Last reply
          0
          • B bonzaiholding

            If i want to create an application without any console and without any form that for example: 1. every 20 hours send an email 2. backup some folder or doing anything without the user interaction. 3. Will write a log to a file. 4. will run a process if some event occur. I know that i can make a form application but then i need to mark the form with 0% Opacity. That will take a lot of memory for the process. What is the best way?

            N Offline
            N Offline
            Natural_Demon
            wrote on last edited by
            #6

            you can't make an application without a window. but you can hide it. you can make a DLL and hook it windows explorer, like a service or something. but don't ask me how to do it, because i never tried

            Bad = knowing 2 much

            S M 2 Replies Last reply
            0
            • N Natural_Demon

              you can't make an application without a window. but you can hide it. you can make a DLL and hook it windows explorer, like a service or something. but don't ask me how to do it, because i never tried

              Bad = knowing 2 much

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #7

              Natural_Demon wrote:

              you can't make an application without a window.

              That is only expection for service. They don't have any window.

              1 Reply Last reply
              0
              • N Natural_Demon

                you can't make an application without a window. but you can hide it. you can make a DLL and hook it windows explorer, like a service or something. but don't ask me how to do it, because i never tried

                Bad = knowing 2 much

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #8

                Your sig says it all - you are quite wrong. A windows/web service does not cannot have a form. This is lousy advice, although admitting you have no idea at least puts it in context. Please be a little more careful about what advice you give. If you had been the first responder and the asker was a newbie then you may have damaged a potential developer.

                Never underestimate the power of human stupidity RAH

                N 2 Replies Last reply
                0
                • M Mycroft Holmes

                  Your sig says it all - you are quite wrong. A windows/web service does not cannot have a form. This is lousy advice, although admitting you have no idea at least puts it in context. Please be a little more careful about what advice you give. If you had been the first responder and the asker was a newbie then you may have damaged a potential developer.

                  Never underestimate the power of human stupidity RAH

                  N Offline
                  N Offline
                  Natural_Demon
                  wrote on last edited by
                  #9

                  eh, i remember i asked the same question when i played with MFC c++ 5,6 years ago. it's impossible for an normal application to operate without a form/cmd. than as solution, i said, you can write a DLL and hooked it the windows explorer, be it as service or something else, like a virus.

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Windows.Forms;
                  using System.Threading;

                  namespace nowindow_application
                  {
                  static class Program
                  {
                  /// <summary>
                  /// The main entry point for the application.
                  /// </summary>
                  [STAThread]
                  static void Main()
                  {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
                  //MessageBox.Show(bobo(1, 2).ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  Thread.Sleep(1000);
                  Main();
                  //Application.Run(new Form1(bobo(1, 2)));
                  }

                      private static int bobo(int a, int b)
                      {
                          return (a + b);
                      }
                  }
                  

                  }

                  this application wil not not produce an executable file using visual studio 2008 //MessageBox.Show(bobo(1, 2).ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information); uncomment this file and you have a executable file in your bin folder. so you can't build a application without a CMD or form layout. i dind't spread any false hope or something, i asked this question before.

                  Bad = knowing 2 much

                  1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    Your sig says it all - you are quite wrong. A windows/web service does not cannot have a form. This is lousy advice, although admitting you have no idea at least puts it in context. Please be a little more careful about what advice you give. If you had been the first responder and the asker was a newbie then you may have damaged a potential developer.

                    Never underestimate the power of human stupidity RAH

                    N Offline
                    N Offline
                    Natural_Demon
                    wrote on last edited by
                    #10

                    or try to compile this

                    using System;
                    using System.Collections.Generic;
                    using System.Linq;
                    using System.Windows.Forms;
                    using System.Threading;

                    namespace nowindow_application
                    {
                    static class Program
                    {
                    /// <summary>
                    /// The main entry point for the application.
                    /// </summary>
                    [STAThread]
                    static void Main()
                    {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    //MessageBox.Show(bobo(1, 2).ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    bobo(1, 2);
                    Thread.Sleep(1000);
                    Main();
                    //Application.Run(new Form1(bobo(1, 2)));
                    }

                        private static int bobo(int a, int b)
                        {
                            return (a + b);
                        }
                    }
                    

                    }

                    Bad = knowing 2 much

                    A 1 Reply Last reply
                    0
                    • N Natural_Demon

                      or try to compile this

                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Windows.Forms;
                      using System.Threading;

                      namespace nowindow_application
                      {
                      static class Program
                      {
                      /// <summary>
                      /// The main entry point for the application.
                      /// </summary>
                      [STAThread]
                      static void Main()
                      {
                      Application.EnableVisualStyles();
                      Application.SetCompatibleTextRenderingDefault(false);
                      //MessageBox.Show(bobo(1, 2).ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                      bobo(1, 2);
                      Thread.Sleep(1000);
                      Main();
                      //Application.Run(new Form1(bobo(1, 2)));
                      }

                          private static int bobo(int a, int b)
                          {
                              return (a + b);
                          }
                      }
                      

                      }

                      Bad = knowing 2 much

                      A Offline
                      A Offline
                      Alan N
                      wrote on last edited by
                      #11

                      Hi, What's your point here? Apart from the recursive call to Main there is nothing that would prevent your example from running to completion. When a program is compiled as a console application then a window, the console, is always created. Counter intuitively a windows application only has a message loop and window if the programmer writes the appropriate code, usually Application.Run(new Form1());. A simple windowless windows application does not show in the taskbar but will be present in Task Manager's process list.

                      static void Main() {
                        System.IO.File.AppendAllText(
                          "log.txt",
                          "NoWindow started at " + System.DateTime.Now.ToString() + System.Environment.NewLine);
                        System.Threading.Thread.Sleep(20 \* 1000);
                        System.IO.File.AppendAllText(
                          "log.txt",
                          "and ended at " + System.DateTime.Now.ToString() + System.Environment.NewLine);
                      }
                      

                      Alan.

                      N 1 Reply Last reply
                      0
                      • A Alan N

                        Hi, What's your point here? Apart from the recursive call to Main there is nothing that would prevent your example from running to completion. When a program is compiled as a console application then a window, the console, is always created. Counter intuitively a windows application only has a message loop and window if the programmer writes the appropriate code, usually Application.Run(new Form1());. A simple windowless windows application does not show in the taskbar but will be present in Task Manager's process list.

                        static void Main() {
                          System.IO.File.AppendAllText(
                            "log.txt",
                            "NoWindow started at " + System.DateTime.Now.ToString() + System.Environment.NewLine);
                          System.Threading.Thread.Sleep(20 \* 1000);
                          System.IO.File.AppendAllText(
                            "log.txt",
                            "and ended at " + System.DateTime.Now.ToString() + System.Environment.NewLine);
                        }
                        

                        Alan.

                        N Offline
                        N Offline
                        Natural_Demon
                        wrote on last edited by
                        #12

                        hi, i have been playing with you code. i tried with threading and other methods. creating endless/limited loops. again .... whitout System.Threading.Thread.Sleep(20 * 1000); or MessageBox you code want compile, wel it doesn't produce an executable. i have achieved 99% cpu usage on a intel 9450. i think this is a very lousy methode off programming. to get something valueble on this methode of programming.

                            static void Main()
                            {
                                begin:
                                if (!testLoop())
                                {
                                    // System.Threading.Thread.Sleep(1 \* 1000);
                                    // MessageBox.Show("new", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    goto begin;
                                }
                                
                            }
                        
                            private static bool testLoop()
                            {
                                while (baba != 101)
                                {
                                    //Thread.Sleep(1 \* 100);
                                    baba++;
                                }
                                baba = 0;
                                return false;
                            }
                        

                        this code comsumes 25% cpu usages and is self sustainable. but it doesn't produce an executable. but if you uncomment System.Threading.Thread.Sleep(1 * 1000); it wil compile but terribly remove the realtime feeling. it's like imitating the Assembler

                        Bad = knowing 2 much

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups