none
How to prevent thread form being stopped/aborted? RRS feed

  • Question

  • I'm not sure if it's a CLR related issue but at the same time i can't say it isn't.

    The problem is as follows: I have created a windows forms user control that spawns a thread(running a form). The thread is not a background thread and it's not supposed to exit until the form gets closed. It works as desired when the control is hosted in a windows forms application. The problem starts when i want to host it inside a html page. All works fine as long as the page containing the control is opened. Things get a bit weird when i redirect or close the tab(not the window; more tabs are opened). Exactly 1 minute from this moment the thread gets aborted.

    public partial class IEControl : UserControl
     {
     public IEControl()
     {
      InitializeComponent();
     }
    
     private System.Threading.Thread t;
     private MainForm mf;
    
     private void IEControl_Load(object sender, EventArgs e)
     {
      GoThread();
     }
    
     public void GoThread()
     {
      try
      {
      t = new System.Threading.Thread(RunForm);
      t.IsBackground = false;
      t.Start();
      }
      catch (Exception ex)
      {
      MessageBox.Show(ex.Message);
      }
     }
    
     private void RunForm()
     {
      mf = new MainForm();
      Application.Run(mf);
      GC.KeepAlive(mf);
      GC.KeepAlive(this);
     }
    }
    

    I'm a bit confused at this point. Where could I get any information on this topic if it's not a CLR/GC related issue.

    Wednesday, August 25, 2010 12:27 PM

All replies

  • The ASP.NET host ignores threads you create on your own.  It is free to discard the AppDomain for numerous reasons, such as automatic recycling, too much memory usage, timer expired, etc.  These aspects are configurable.  See: http://msdn.microsoft.com/en-us/library/ms228159.aspx  Other settings can be found in the IIS worker process configuration.

    Microsoft maintains a separate forums system for ASP.NET, and ASP.NET is off-topic for this forum.  I encourage you to post at: http://forums.asp.net

     

     

    Wednesday, August 25, 2010 11:17 PM
  • It's i no way related to ASP.net or any other web technology. Windows Forms UserControls can be hosted in html, asp, asp.net, php and anything else that ends up as a page in web browser. It's either CLR or Internet Explorer issue, because it runs completely on client side.
    Thursday, August 26, 2010 7:50 AM