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. How to add code of form to windows service?

How to add code of form to windows service?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 2 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.
  • H Offline
    H Offline
    haroon1980
    wrote on last edited by
    #1

    I have one schedule application done with a form having several controls. Now i want to create windowsservice and want to add the task to OnStart() method but what should i add? If you know what I mean? I mean i have form "Form1.cs"with events one different buttons and "schedule.cs" having main method to run the form. Now when i add new item or new project as windows service both have then main methods? Please advice? :confused:

    K 1 Reply Last reply
    0
    • H haroon1980

      I have one schedule application done with a form having several controls. Now i want to create windowsservice and want to add the task to OnStart() method but what should i add? If you know what I mean? I mean i have form "Form1.cs"with events one different buttons and "schedule.cs" having main method to run the form. Now when i add new item or new project as windows service both have then main methods? Please advice? :confused:

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      A windows service can call other dlls. I would suggest putting the code that is in form1.cs in a new class library. Then add a windows service add a reference to the class library. Then the windows service can call the same code the windows form calls. Ben

      H 1 Reply Last reply
      0
      • K kubben

        A windows service can call other dlls. I would suggest putting the code that is in form1.cs in a new class library. Then add a windows service add a reference to the class library. Then the windows service can call the same code the windows form calls. Ben

        H Offline
        H Offline
        haroon1980
        wrote on last edited by
        #3

        What you mean ben? Are you saying create a different project or what because class library cannot be added in this project. I tried to create clean class library project and this form1.cs code doesnt fit there because it complains abt different controls. I am now kind of confused a lot :((

        K 1 Reply Last reply
        0
        • H haroon1980

          What you mean ben? Are you saying create a different project or what because class library cannot be added in this project. I tried to create clean class library project and this form1.cs code doesnt fit there because it complains abt different controls. I am now kind of confused a lot :((

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          That is true, you can not put windows controls in your class library. You should not try to do this anyway. What should go in the class library is the methods that are in the form1.cs that use the data from the windows controls. You should have methods that get called by button click events etc. Then you can add a class library project to your solution and move the code to there. As long as the windows project has a reference to the class library everything should work. Ben

          H 1 Reply Last reply
          0
          • K kubben

            That is true, you can not put windows controls in your class library. You should not try to do this anyway. What should go in the class library is the methods that are in the form1.cs that use the data from the windows controls. You should have methods that get called by button click events etc. Then you can add a class library project to your solution and move the code to there. As long as the windows project has a reference to the class library everything should work. Ben

            H Offline
            H Offline
            haroon1980
            wrote on last edited by
            #5

            I know that application is same as mine but i dont know how to do registry things.. I mean how to save my data in registry? ok i think i am misleading everybody. Following what i have and what i want to do I have form1.cs which have different events and what i am doing on this form is adding some tasks in ListView. Now the next task is to add scheduling functionality to those tasks. How would you start implementing it? Can somebody please guide me the steps of tasks as how to add schedule functionality? Yes I need a kind of service which will run any tasks which were added in listview in Form1.cs. how would you implement that? Anu guidance please? :confused:

            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