Manage Multithreading with time interval in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sflaish
    New Member
    • Dec 2010
    • 1

    #1

    Manage Multithreading with time interval in C#

    The following code will create a new thread each time you enter a new well uid in the textbox by clicking the command button:
    I would to know how to manage make each new thread run every 10 minutes for example and how i manage my threads in case if i need to stop a specific thread assuming that i'll end up with 10 or more threads running at the same time every 10 minutes.

    Thanks in advance



    [CODE]
    namespace WindowsFormsApp lication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }


    public class WitsmlJob
    {

    private string WELLUID;


    public WitsmlJob(strin g welluid)
    {
    WELLUID = welluid;

    }


    public void Run()
    {
    WitsmlServer.UO M = UomBase.Imperia l;
    List<WitsmlWell bore> wells;
    //List<WitsmlLog> Logs;

    var svr = new WitsmlServer("h ttps://server.com/witsml/store/store.asmx", "username", "password", WitsmlVersion.V ERSION_1_3_1,
    new Capabilities(Wi tsmlVersion, "aaaa", "", "5555551212 ", "COMP", "ORG", "FRIENDLYNA ME", "0.5a"));

    wells = svr.get<WitsmlW ellbore>(new WitsmlQuery(), WELLUID); //Get Wellbore uid and name for a specific well uid
    FileStream Logfile = new FileStream(Appl ication.Startup Path + "\\test.txt ", FileMode.Append , FileAccess.Writ e);

    StreamWriter SW = new StreamWriter(Lo gfile);



    foreach (var well in wells)
    {
    SW.WriteLine(we ll.getName() + " " + well.getId() + " " + DateTime.Now);

    }

    SW.Close ();
    Logfile.Close() ;
    }
    }



    private void button1_Click(o bject sender, EventArgs e)
    {


    // Create WITSML job
    WitsmlJob job = new WitsmlJob(textB ox1.Text);
    new Thread(new ThreadStart(job .Run)).Start();



    }

    private void Form1_Load(obje ct sender, EventArgs e)
    {

    }
    }
    }
    [/CODE}
Working...