How to Make a C# Background App



Hello. How are you? I’m good.

Today, I’m going to show you how to make a background app. When I say a background app, I mean a thread that runs after a form closes.

First, we need a form. Make it as small as possible so just the upper right buttons show. This is just so you won’t notice it easily. Then, left click and go to “view code”. Here is were we will write the code.

We will be using System.Threading, so write at the top:

using System.Threading;

Okay. Now we make the thread make the event Form1_load. After that we write some code in there it should look like this:

private void Form1_Load(object sender, EventArgs e)
      var link1 = new Form1();
      Thread thread1 = new Thread(link1.start1);

Now we have a thread start and the form auto-closes, so we just need to make a starting method:

public void start1()
    //code goes here.

I hope this helps you. The reason I made this How-To is because I couldn’t find an existing one.

Good Day!

(The C# Dude) #2

I always just comment out the “Application.Run(new Form1)” in the Programm.cs, so that not even the little Form is shown. I think the 2 lines above could be removed either, but it’s a tradition to do it like this :grin:. See here:

static void Main()
    //Application.Run(new Form1);

Works great!

//Edit: This has to be done in a Windows Forms Application (As always: Tested on Win7/Visual Studio 2015)

//Edit 2: And welcome! It’s nice to see more C# interested dudes here :slight_smile: !

(oaktree) #3

@TheDoctor: I suggest you use the code-formatting features of the post editor instead of posting screenshots.


i guess so but having a lag nuke is all ways fun you know how those exe(e.g: sonic.exe) game’s work thay close the main window and have the threads run in the background that’s the main reason i wrote this article
because i wanted to make an app that ran but didn’t lose stuff in strings and char array’s :slight_smile:
edit1: after closing the main window

(The C# Dude) #5

You’re right :slight_smile:. Another bad habit :grin:.

//Edited above reply

(system) #6

This topic was automatically closed after 30 days. New replies are no longer allowed.