Thread won't start...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • taylorjonl@gmail.com

    Thread won't start...

    I am completely baffled. I am writting a daemon application for my
    work to save me some time. The application works fine at my home but
    won't work right here at work. Basically I have a MainForm what has a
    Start/Stop button that starts and stops the processing thread.

    private void StartButton_Cli ck(object sender, System.EventArg s e)
    {
    if( bStopSignal )
    {
    // disable controls that aren't valid when running
    StartButton.Ena bled = false;
    Issue12CheckBox .Enabled = false;
    Issue28CheckBox .Enabled = false;
    Issue29CheckBox .Enabled = false;

    // enable controls that are valid when running
    StopButton.Enab led = true;

    // start the processing thread
    bStopSignal = false;
    MessageBox.Show ( "Starting Processing Thread" );
    (pProcessingThr ead = new Thread( new ThreadStart( ThreadProc )
    )).Start();
    }
    }


    private void StopButton_Clic k(object sender, System.EventArg s e)
    {
    // enable controls that are valid when stopped
    StartButton.Ena bled = true;
    Issue12CheckBox .Enabled = true;
    Issue28CheckBox .Enabled = true;
    Issue29CheckBox .Enabled = true;

    // disable controls that aren't valid when stopped
    StopButton.Enab led = false;

    // stop the processing thread
    bStopSignal = true;
    if( pProcessingThre ad != null )
    {
    MessageBox.Show ( "Stopping Processing Thread" );
    pProcessingThre ad.Join();
    pProcessingThre ad = null;
    }
    }



    private void ThreadProc()
    {
    MessageBox.Show ( "Please browse to the issue viewer base URL to
    start" );

    // temporary code because I am lazy
    pWebBrowser.Sho w(); pWebBrowser.Bri ngToFront();
    pWebBrowser.Doc umentComplete.R eset();
    pWebBrowser.Doc umentComplete.W aitOne();
    string starturl = pWebBrowser.Doc ument.url;

    string member = null;
    while( !bStopSignal )
    {
    }
    }

    The above are the 3 important functions, the ThreadProc has been
    trimmed of the logic in the while block, otherwise no difference from
    my code.

    When I click the start button I get the message box stating it is
    starting the thread but don't get the message from the ThreadProc
    function. Stop gives a message that it is stopping. It isn't starting
    the thread like it should.

    I am wondering if anyone can give me any feedback on possible cause. I
    am wondering if I don't have access rights on my computer to start a
    thread? Is this possible, if so would the program execute without
    informing me it can't start the thread?

    Keep in mind I can't debug it here at work because I don't have a
    debugger and can't install a debugger.

  • Jon Skeet [C# MVP]

    #2
    Re: Thread won't start...

    taylorj...@gmai l.com wrote:[color=blue]
    > I am completely baffled. I am writting a daemon application for my
    > work to save me some time. The application works fine at my home but
    > won't work right here at work. Basically I have a MainForm what has a
    > Start/Stop button that starts and stops the processing thread.[/color]

    Could you post a short but complete program that demonstrates the
    problem?
    You shouldn't need much to show it. See
    http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
    that.

    Note that your bStopSignal variable *must* be volatile (or a
    synchronized property) for your code to be thread-safe.
    See http://www.pobox.com/~skeet/csharp/t...latility.shtml for
    more on that.

    Also note that you shouldn't use UI components created in one thread on
    another thread. See
    http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more than
    that. (My guess is that your web browser is a UI component.) That
    probably isn't the problem here (if you aren't seeing the message box
    from the start of the other thread) but it may well bite you as soon as
    you get past this initial problem.

    Jon

    Comment

    • taylorjonl

      #3
      Re: Thread won't start...

      using System;
      using System.Drawing;
      using System.Collecti ons;
      using System.Componen tModel;
      using System.Windows. Forms;
      using System.Data;
      using System.IO;
      using System.Threadin g;

      namespace Issue
      {
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class MainForm : System.Windows. Forms.Form
      {
      private System.Windows. Forms.Label MemberLabel;
      internal System.Windows. Forms.MainMenu MainMenu;
      private System.Windows. Forms.MenuItem menuItem1;
      private System.Windows. Forms.MenuItem menuItem2;
      private System.Windows. Forms.MenuItem menuItem3;
      private System.Windows. Forms.MenuItem menuItem4;
      private System.Windows. Forms.TextBox MemberTextBox;
      private System.Windows. Forms.Button AddButton;
      private System.Windows. Forms.ListBox QueuedListBox;
      private System.Windows. Forms.StatusBar statusBar1;
      private System.Windows. Forms.NotifyIco n NotifyIcon;
      private System.Componen tModel.IContain er components;
      private System.Windows. Forms.Button StartButton;
      private System.Windows. Forms.Button StopButton;
      private System.Windows. Forms.GroupBox IssueCloseGroup ;
      private System.Windows. Forms.CheckBox Issue12CheckBox ;
      private System.Windows. Forms.CheckBox Issue28CheckBox ;
      private System.Windows. Forms.CheckBox Issue29CheckBox ;
      private System.Windows. Forms.MenuItem ImportMenuItem;
      private System.Windows. Forms.MenuItem menuItem6;
      private System.Windows. Forms.MenuItem ExitMenuItem;
      private System.Windows. Forms.OpenFileD ialog ImportFileDialo g;

      // member processing variables
      private Thread pProcessingThre ad;
      private bool bStopSignal;
      private Queue pMemberQueue;

      public MainForm()
      {
      //
      // Required for Windows Form Designer support
      //
      InitializeCompo nent();

      //
      // TODO: Add any constructor code after InitializeCompo nent call
      //

      // setup member processing variables
      bStopSignal = true;
      pMemberQueue = new Queue();
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
      if( disposing )
      {
      if (components != null)
      {
      components.Disp ose();
      }
      }
      base.Dispose( disposing );
      }


      /// <summary>
      /// </summary>
      private void SyncLists()
      {
      QueuedListBox.I tems.Clear();
      object[] contents = new object[pMemberQueue.Co unt];
      pMemberQueue.Co pyTo( contents, 0 );
      QueuedListBox.I tems.AddRange( contents );
      }


      /// <summary>
      /// </summary>
      private void ThreadProc()
      {
      MessageBox.Show ( "Please browse to the issue viewer base URL to
      start" );

      string member = null;
      while( !bStopSignal )
      {
      // get the next member
      lock( pMemberQueue )
      {
      if( pMemberQueue.Co unt < 1 )
      {
      Thread.Sleep( 100 );
      continue;
      }
      member = (string)pMember Queue.Dequeue() ;

      // sync the QueuedListBox and pMemberQueue contencts
      SyncLists();

      ///////////////////////////////////////////////////////////
      // Busines logic was here
      ///////////////////////////////////////////////////////////
      }
      }
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeCompo nent()
      {
      this.components = new System.Componen tModel.Containe r();
      System.Resource s.ResourceManag er resources = new
      System.Resource s.ResourceManag er(typeof(MainF orm));
      this.MemberLabe l = new System.Windows. Forms.Label();
      this.MainMenu = new System.Windows. Forms.MainMenu( );
      this.menuItem1 = new System.Windows. Forms.MenuItem( );
      this.menuItem2 = new System.Windows. Forms.MenuItem( );
      this.menuItem3 = new System.Windows. Forms.MenuItem( );
      this.menuItem4 = new System.Windows. Forms.MenuItem( );
      this.MemberText Box = new System.Windows. Forms.TextBox() ;
      this.AddButton = new System.Windows. Forms.Button();
      this.QueuedList Box = new System.Windows. Forms.ListBox() ;
      this.statusBar1 = new System.Windows. Forms.StatusBar ();
      this.NotifyIcon = new
      System.Windows. Forms.NotifyIco n(this.componen ts);
      this.StartButto n = new System.Windows. Forms.Button();
      this.StopButton = new System.Windows. Forms.Button();
      this.IssueClose Group = new System.Windows. Forms.GroupBox( );
      this.Issue29Che ckBox = new System.Windows. Forms.CheckBox( );
      this.Issue28Che ckBox = new System.Windows. Forms.CheckBox( );
      this.Issue12Che ckBox = new System.Windows. Forms.CheckBox( );
      this.ImportMenu Item = new System.Windows. Forms.MenuItem( );
      this.menuItem6 = new System.Windows. Forms.MenuItem( );
      this.ExitMenuIt em = new System.Windows. Forms.MenuItem( );
      this.ImportFile Dialog = new System.Windows. Forms.OpenFileD ialog();
      this.IssueClose Group.SuspendLa yout();
      this.SuspendLay out();
      //
      // MemberLabel
      //
      this.MemberLabe l.Location = new System.Drawing. Point(8, 8);
      this.MemberLabe l.Name = "MemberLabe l";
      this.MemberLabe l.Size = new System.Drawing. Size(48, 23);
      this.MemberLabe l.TabIndex = 0;
      this.MemberLabe l.Text = "Member";
      //
      // MainMenu
      //
      this.MainMenu.M enuItems.AddRan ge(new System.Windows. Forms.MenuItem[]
      {
      this.menuItem1,
      this.menuItem2,
      this.menuItem3,
      this.menuItem4} );
      //
      // menuItem1
      //
      this.menuItem1. Index = 0;
      this.menuItem1. MenuItems.AddRa nge(new
      System.Windows. Forms.MenuItem[] {
      this.ImportMenu Item,
      this.menuItem6,
      this.ExitMenuIt em});
      this.menuItem1. Text = "&File";
      //
      // menuItem2
      //
      this.menuItem2. Index = 1;
      this.menuItem2. Text = "&Edit";
      //
      // menuItem3
      //
      this.menuItem3. Index = 2;
      this.menuItem3. Text = "&View";
      //
      // menuItem4
      //
      this.menuItem4. Index = 3;
      this.menuItem4. Text = "&Help";
      //
      // MemberTextBox
      //
      this.MemberText Box.Location = new System.Drawing. Point(56, 8);
      this.MemberText Box.Name = "MemberTextBox" ;
      this.MemberText Box.Size = new System.Drawing. Size(168, 20);
      this.MemberText Box.TabIndex = 1;
      this.MemberText Box.Text = "";
      //
      // AddButton
      //
      this.AddButton. Location = new System.Drawing. Point(232, 8);
      this.AddButton. Name = "AddButton" ;
      this.AddButton. Size = new System.Drawing. Size(50, 23);
      this.AddButton. TabIndex = 2;
      this.AddButton. Text = "Add";
      this.AddButton. Click += new
      System.EventHan dler(this.AddBu tton_Click);
      //
      // QueuedListBox
      //
      this.QueuedList Box.Location = new System.Drawing. Point(8, 40);
      this.QueuedList Box.Name = "QueuedListBox" ;
      this.QueuedList Box.Size = new System.Drawing. Size(272, 108);
      this.QueuedList Box.TabIndex = 3;
      //
      // statusBar1
      //
      this.statusBar1 .Location = new System.Drawing. Point(0, 245);
      this.statusBar1 .Name = "statusBar1 ";
      this.statusBar1 .ShowPanels = true;
      this.statusBar1 .Size = new System.Drawing. Size(288, 22);
      this.statusBar1 .TabIndex = 4;
      this.statusBar1 .Text = "statusBar1 ";
      //
      // NotifyIcon
      //
      // this.NotifyIcon .Icon =
      ((System.Drawin g.Icon)(resourc es.GetObject("N otifyIcon.Icon" )));
      this.NotifyIcon .Text = "Issue Closing Daemon";
      this.NotifyIcon .Visible = true;
      this.NotifyIcon .DoubleClick += new
      System.EventHan dler(this.Notif yIcon_DoubleCli ck);
      //
      // StartButton
      //
      this.StartButto n.Location = new System.Drawing. Point(120, 160);
      this.StartButto n.Name = "StartButto n";
      this.StartButto n.Size = new System.Drawing. Size(160, 32);
      this.StartButto n.TabIndex = 5;
      this.StartButto n.Text = "Start";
      this.StartButto n.Click += new
      System.EventHan dler(this.Start Button_Click);
      //
      // StopButton
      //
      this.StopButton .Enabled = false;
      this.StopButton .Location = new System.Drawing. Point(120, 208);
      this.StopButton .Name = "StopButton ";
      this.StopButton .Size = new System.Drawing. Size(160, 32);
      this.StopButton .TabIndex = 6;
      this.StopButton .Text = "Stop";
      this.StopButton .Click += new
      System.EventHan dler(this.StopB utton_Click);
      //
      // IssueCloseGroup
      //
      this.IssueClose Group.Controls. Add(this.Issue2 9CheckBox);
      this.IssueClose Group.Controls. Add(this.Issue2 8CheckBox);
      this.IssueClose Group.Controls. Add(this.Issue1 2CheckBox);
      this.IssueClose Group.Location = new System.Drawing. Point(8, 152);
      this.IssueClose Group.Name = "IssueCloseGrou p";
      this.IssueClose Group.Size = new System.Drawing. Size(104, 88);
      this.IssueClose Group.TabIndex = 7;
      this.IssueClose Group.TabStop = false;
      this.IssueClose Group.Text = "Issues to close";
      //
      // Issue29CheckBox
      //
      this.Issue29Che ckBox.Checked = true;
      this.Issue29Che ckBox.CheckStat e =
      System.Windows. Forms.CheckStat e.Checked;
      this.Issue29Che ckBox.Location = new System.Drawing. Point(8, 64);
      this.Issue29Che ckBox.Name = "Issue29CheckBo x";
      this.Issue29Che ckBox.Size = new System.Drawing. Size(72, 15);
      this.Issue29Che ckBox.TabIndex = 2;
      this.Issue29Che ckBox.Text = "Issue 29";
      //
      // Issue28CheckBox
      //
      this.Issue28Che ckBox.Checked = true;
      this.Issue28Che ckBox.CheckStat e =
      System.Windows. Forms.CheckStat e.Checked;
      this.Issue28Che ckBox.Location = new System.Drawing. Point(8, 40);
      this.Issue28Che ckBox.Name = "Issue28CheckBo x";
      this.Issue28Che ckBox.Size = new System.Drawing. Size(72, 15);
      this.Issue28Che ckBox.TabIndex = 1;
      this.Issue28Che ckBox.Text = "Issue 28";
      //
      // Issue12CheckBox
      //
      this.Issue12Che ckBox.Location = new System.Drawing. Point(8, 16);
      this.Issue12Che ckBox.Name = "Issue12CheckBo x";
      this.Issue12Che ckBox.Size = new System.Drawing. Size(72, 15);
      this.Issue12Che ckBox.TabIndex = 0;
      this.Issue12Che ckBox.Text = "Issue 12";
      //
      // ImportMenuItem
      //
      this.ImportMenu Item.Index = 0;
      this.ImportMenu Item.Text = "&Import File";
      this.ImportMenu Item.Click += new
      System.EventHan dler(this.Impor tMenuItem_Click );
      //
      // menuItem6
      //
      this.menuItem6. Index = 1;
      this.menuItem6. Text = "-";
      //
      // ExitMenuItem
      //
      this.ExitMenuIt em.Index = 2;
      this.ExitMenuIt em.Text = "&Exit";
      this.ExitMenuIt em.Click += new
      System.EventHan dler(this.ExitM enuItem_Click);
      //
      // MainForm
      //
      this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
      this.ClientSize = new System.Drawing. Size(288, 267);
      this.Controls.A dd(this.IssueCl oseGroup);
      this.Controls.A dd(this.StopBut ton);
      this.Controls.A dd(this.StartBu tton);
      this.Controls.A dd(this.statusB ar1);
      this.Controls.A dd(this.QueuedL istBox);
      this.Controls.A dd(this.AddButt on);
      this.Controls.A dd(this.MemberT extBox);
      this.Controls.A dd(this.MemberL abel);
      this.FormBorder Style =
      System.Windows. Forms.FormBorde rStyle.FixedDia log;
      this.MaximizeBo x = false;
      this.Menu = this.MainMenu;
      this.Name = "MainForm";
      this.Text = "Issue Closing Daemon";
      this.Resize += new System.EventHan dler(this.MainF orm_Resize);
      this.Closing += new
      System.Componen tModel.CancelEv entHandler(this .MainForm_Closi ng);
      this.IssueClose Group.ResumeLay out(false);
      this.ResumeLayo ut(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
      // start application
      Application.Run ( new MainForm() );
      }

      #region Form Event Handlers

      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void AddButton_Click (object sender, System.EventArg s e)
      {
      // add member to queue and clear text box
      pMemberQueue.En queue( MemberTextBox.T ext ); MemberTextBox.C lear();

      // update the QueuedListBox
      SyncLists();
      }


      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void MainForm_Closin g(object sender,
      System.Componen tModel.CancelEv entArgs e)
      {
      // stop the processing thread.
      bStopSignal = true;
      if( pProcessingThre ad != null )
      pProcessingThre ad.Join();
      }


      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void MainForm_Resize (object sender, System.EventArg s e)
      {
      // hide the form if minimize requested
      if( FormWindowState .Minimized == this.WindowStat e )
      this.Hide();
      }


      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void NotifyIcon_Doub leClick(object sender, System.EventArg s
      e)
      {
      // show MainForm and set to appropriate state
      this.Show(); this.WindowStat e = FormWindowState .Normal;
      }


      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void StartButton_Cli ck(object sender, System.EventArg s e)
      {
      if( bStopSignal )
      {
      // disable controls that aren't valid when running
      StartButton.Ena bled = false;
      Issue12CheckBox .Enabled = false;
      Issue28CheckBox .Enabled = false;
      Issue29CheckBox .Enabled = false;

      // enable controls that are valid when running
      StopButton.Enab led = true;

      // start the processing thread
      bStopSignal = false;
      MessageBox.Show ( "Starting Processing Thread" );
      (pProcessingThr ead = new Thread( new ThreadStart( ThreadProc )
      )).Start();
      }
      }


      /// <summary>
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void StopButton_Clic k(object sender, System.EventArg s e)
      {
      // enable controls that are valid when stopped
      StartButton.Ena bled = true;
      Issue12CheckBox .Enabled = true;
      Issue28CheckBox .Enabled = true;
      Issue29CheckBox .Enabled = true;

      // disable controls that aren't valid when stopped
      StopButton.Enab led = false;

      // stop the processing thread
      bStopSignal = true;
      if( pProcessingThre ad != null )
      {
      MessageBox.Show ( "Stopping Processing Thread" );
      pProcessingThre ad.Join();
      pProcessingThre ad = null;
      }
      }


      private void ExitMenuItem_Cl ick(object sender, System.EventArg s e)
      {

      }

      private void ImportMenuItem_ Click(object sender, System.EventArg s e)
      {
      if( ImportFileDialo g.ShowDialog() == DialogResult.OK )
      {
      try
      {
      using( StreamReader reader = new StreamReader(
      ImportFileDialo g.FileName ) )
      {
      string line = null;
      while( ( line = reader.ReadLine () ) != null )
      {
      // add member to queue and clear text box
      pMemberQueue.En queue( line );
      }

      // update the QueuedListBox
      SyncLists();
      }
      }
      catch( Exception ex )
      {
      MessageBox.Show ( "Exception: " + ex.ToString() );
      }
      }
      }

      #endregion Form Event Handlers
      }
      }

      I commented the Icon setting line because I wasn't sure if it was
      needed. I can't verify that compiles, it should, all I did was remove
      the references to the other forms which aren't valid for this problem.

      Thanks for any help, this is driving me nuts.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Thread won't start...

        taylorjonl wrote:

        <snip mammoth code>

        That's really not short, is it?
        [color=blue]
        >From the page I referred you to: "Anything which is unnecessary should[/color]
        be removed."

        Do you really believe that there's nothing in the code you posted which
        isn't relevant to the question? How about the checkboxes, the text box
        etc? As it is, there's far too much code to look through. If you pare
        down the code to the bare minimum, you may well find the problem
        yourself.

        You definitely *do* have a problem calling SyncLists() inside
        ThreadProc() though, for the reasons I gave before.
        [color=blue]
        > I commented the Icon setting line because I wasn't sure if it was
        > needed. I can't verify that compiles, it should, all I did was remove
        > the references to the other forms which aren't valid for this problem.[/color]

        Why can't you verify that it compiles? Just bring up a command line
        with the appropriate variables set (there's a batch file to set them if
        you want), cut and paste your code into a text file, and run csc.
        That's what I'd be doing, so I don't see what's likely to stop you from
        being able to do the same.

        Jon

        Comment

        • taylorjonl

          #5
          Re: Thread won't start...

          Sorry if I pasted too much code, didn't know how much you wanted.

          using System;
          using System.Drawing;
          using System.Collecti ons;
          using System.Componen tModel;
          using System.Windows. Forms;
          using System.Data;
          using System.IO;
          using System.Threadin g;

          namespace Issue
          {
          /// <summary>
          /// Summary description for Form1.
          /// </summary>
          public class MainForm : System.Windows. Forms.Form
          {
          private System.Componen tModel.IContain er components;
          private System.Windows. Forms.Button StartButton;
          private System.Windows. Forms.Button StopButton;

          // member processing variables
          private Thread pProcessingThre ad;
          private bool bStopSignal;

          public MainForm()
          {
          //
          // Required for Windows Form Designer support
          //
          InitializeCompo nent();

          //
          // TODO: Add any constructor code after InitializeCompo nent call
          //

          // setup member processing variables
          bStopSignal = true;
          }

          /// <summary>
          /// Clean up any resources being used.
          /// </summary>
          protected override void Dispose( bool disposing )
          {
          if( disposing )
          {
          if (components != null)
          {
          components.Disp ose();
          }
          }
          base.Dispose( disposing );
          }


          /// <summary>
          /// </summary>
          private void ThreadProc()
          {
          MessageBox.Show ( "Please browse to the issue viewer base URL to
          start" );

          string member = null;
          while( !bStopSignal )
          {
          Thread.Sleep( 100 );
          }
          }

          #region Windows Form Designer generated code
          /// <summary>
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// </summary>
          private void InitializeCompo nent()
          {
          this.components = new System.Componen tModel.Containe r();
          System.Resource s.ResourceManag er resources = new
          System.Resource s.ResourceManag er(typeof(MainF orm));
          this.StartButto n = new System.Windows. Forms.Button();
          this.StopButton = new System.Windows. Forms.Button();

          //
          // StartButton
          //
          this.StartButto n.Location = new System.Drawing. Point(120, 160);
          this.StartButto n.Name = "StartButto n";
          this.StartButto n.Size = new System.Drawing. Size(160, 32);
          this.StartButto n.TabIndex = 5;
          this.StartButto n.Text = "Start";
          this.StartButto n.Click += new
          System.EventHan dler(this.Start Button_Click);
          //
          // StopButton
          //
          this.StopButton .Enabled = false;
          this.StopButton .Location = new System.Drawing. Point(120, 208);
          this.StopButton .Name = "StopButton ";
          this.StopButton .Size = new System.Drawing. Size(160, 32);
          this.StopButton .TabIndex = 6;
          this.StopButton .Text = "Stop";
          this.StopButton .Click += new
          System.EventHan dler(this.StopB utton_Click);
          //
          // MainForm
          //
          this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
          this.ClientSize = new System.Drawing. Size(288, 267);
          this.Controls.A dd(this.StopBut ton);
          this.Controls.A dd(this.StartBu tton);
          this.FormBorder Style =
          System.Windows. Forms.FormBorde rStyle.FixedDia log;
          this.MaximizeBo x = false;
          this.Name = "MainForm";
          this.Text = "Issue Closing Daemon";
          this.ResumeLayo ut(false);

          }
          #endregion

          /// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main()
          {
          // start application
          Application.Run ( new MainForm() );
          }


          /// <summary>
          /// </summary>
          /// <param name="sender"></param>
          /// <param name="e"></param>
          private void StartButton_Cli ck(object sender, System.EventArg s e)
          {
          if( bStopSignal )
          {
          // disable controls that aren't valid when running
          StartButton.Ena bled = false;

          // enable controls that are valid when running
          StopButton.Enab led = true;

          // start the processing thread
          bStopSignal = false;
          MessageBox.Show ( "Starting Processing Thread" );
          (pProcessingThr ead = new Thread( new ThreadStart( ThreadProc )
          )).Start();
          }
          }


          /// <summary>
          /// </summary>
          /// <param name="sender"></param>
          /// <param name="e"></param>
          private void StopButton_Clic k(object sender, System.EventArg s e)
          {
          // enable controls that are valid when stopped
          StartButton.Ena bled = true;

          // disable controls that aren't valid when stopped
          StopButton.Enab led = false;

          // stop the processing thread
          bStopSignal = true;
          if( pProcessingThre ad != null )
          {
          MessageBox.Show ( "Stopping Processing Thread" );
          pProcessingThre ad.Join();
          pProcessingThre ad = null;
          }
          }
          }
          }

          That is the bare minimum and I have compile it. It works as expected.
          Something is very wrong in my code. I am going to do another test with
          only the WebBrowser control removed as I would expect this to be the
          cause.

          Sorry about not trying to compile from command line before, I tried to
          that from work a while ago and it crashed my system. I don't have any
          batch file with the environmental variables but just added csc.exe to
          the path and it compiles. If you have this batch file please post it
          because if I can compile at work I can find the problem.

          Thanks for the help, I will post once I have found a solution.

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Thread won't start...

            taylorjonl <taylorjonl@gma il.com> wrote:[color=blue]
            > Sorry if I pasted too much code, didn't know how much you wanted.[/color]

            The hint was in the page I linked to :)

            <snip>
            [color=blue]
            > That is the bare minimum and I have compile it. It works as expected.
            > Something is very wrong in my code. I am going to do another test with
            > only the WebBrowser control removed as I would expect this to be the
            > cause.[/color]

            Right. Now you've got a minimal base, you can gradually add bits until
            it fails.
            [color=blue]
            > Sorry about not trying to compile from command line before, I tried to
            > that from work a while ago and it crashed my system. I don't have any
            > batch file with the environmental variables but just added csc.exe to
            > the path and it compiles. If you have this batch file please post it
            > because if I can compile at work I can find the problem.[/color]

            There should be one that came with Visual Studio. Look under the Visual
            Studio installation directory for vsvars32.bat (VS.NET 2003) or
            vcvarsall.bat (VS 2005).

            --
            Jon Skeet - <skeet@pobox.co m>
            http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
            If replying to the group, please do not mail me too

            Comment

            Working...