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. Thread

Thread

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 4 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.
  • A Offline
    A Offline
    Ammu S
    wrote on last edited by
    #1

    Hello I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.

    R K 2 Replies Last reply
    0
    • A Ammu S

      Hello I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Like this:

      using System;
      using System.Threading;

      namespace BackgroundThread
      {
      class Program
      {
      static void Main(string[] args)
      {
      Thread t = new Thread(BackgroundMethod);
      t.IsBackground = true;
      t.Start();
      Console.ReadLine();
      }

      	private static void BackgroundMethod()
      	{
      		while (true)
      		{
      			Thread.Sleep(1000);
      			Console.WriteLine("Tick");
      		}
      	}
      }
      

      }

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      • A Ammu S

        Hello I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.

        K Offline
        K Offline
        Krishnraj
        wrote on last edited by
        #3

        Try using BackgroundWorker component which u can find in ToolBox of Visual Studio.

        Krishnraj

        M 1 Reply Last reply
        0
        • K Krishnraj

          Try using BackgroundWorker component which u can find in ToolBox of Visual Studio.

          Krishnraj

          M Offline
          M Offline
          Megidolaon
          wrote on last edited by
          #4

          BackGroundWorkers are for forms though, maybe his program doesn't have a form. Though, if you use a form, the BackGroundWorker is the easiest way to go. Just remember to lock any objects while they're being worked on, but beware of dealocks (more than one thread locking the same object).

          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