Results 1 to 7 of 7

Thread: Scheduling Tasks

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Scheduling Tasks

    Hello. I have a small class library, each implementing the ITask interface:
    Code:
    Public Interface ITask
        Property StartTime As DateTime
        Property StopTime As DateTime
        Property RunFrequency As TimeSpan
        Sub Start()
        Function Execute() As Integer
        Sub Finish()
    End Interface
    I'm looking to allow my user to schedule these tasks. Basically a big list of tasks.. each one on it's own thread.
    psuedo: If Now >= startTime and Now <= stopTime, Threading.Thread.Sleep(task.execute())

    What controls could I use to make the scheduling look neat? How would I go about with the actual threading part? Would I need to add a Thread property to my ITask interface?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Scheduling Tasks

    Take a look at JMcIlhinney's thread on adding a pause to your code, if used properly you can do exactly what you're wanting to do:
    Code:
    Run task 1
    Pause -x- time
    Run task 2
    Pause -y- time
    Run task 3
    Pause -z- time
    etc.
    The way that he structured the code, doesn't block the UI and it doesn't use a 'busy wait', which by the way Thread.Sleep will block the UI.
    Last edited by dday9; May 21st, 2013 at 01:08 PM. Reason: Run task 3 not Rune task 3
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Scheduling Tasks

    Quote Originally Posted by Zach_VB6 View Post
    How would I go about with the actual threading part? Would I need to add a Thread property to my ITask interface?
    I think a very important question needs to be answered first: Do you want these ITask implementers to be able to start themselves ? Or do you intend to have a collection based object that takes ITask objects and start them when its their time ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Scheduling Tasks

    Quote Originally Posted by dday9 View Post
    Take a look at JMcIlhinney's thread on adding a pause to your code, if used properly you can do exactly what you're wanting to do:
    Code:
    Run task 1
    Pause -x- time
    Run task 2
    Pause -y- time
    Run task 3
    Pause -z- time
    etc.
    The way that he structured the code, doesn't block the UI and it doesn't use a 'busy wait', which by the way Thread.Sleep will block the UI.
    Thank you for the link. Not sure how to "trigger" the start of the ITask object.
    Quote Originally Posted by Niya View Post
    I think a very important question needs to be answered first: Do you want these ITask implementers to be able to start themselves ? Or do you intend to have a collection based object that takes ITask objects and start them when its their time ?
    I think it would be better if I created a TaskHandler class that handled the collection of ITask objects and would start/stop them appropriately. I think the TaskHandler class should also "paint"/display the current schedule to the user

    Is there a control that would be well suited for a scheduling type thing?

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Scheduling Tasks

    Quote Originally Posted by Zach_VB6 View Post
    Is there a control that would be well suited for a scheduling type thing?
    I'm thinking that a simple grid could work well.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Scheduling Tasks

    Quote Originally Posted by Niya View Post
    I'm thinking that a simple grid could work well.
    I could bind a List(of ITask) to a DataGridView? How do you bind a list?

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Scheduling Tasks

    You could bind a DataGridView by setting its DataSource property. If you do this through the property grid at design time, the designer will generate the columns in the DataGridView for you. At runtime, bind the list. Note though that only public properties are considered in data binding scenarios.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width