I have a situation, I am calling a method asynchronously, which does not
return values. If I make 100 call asynchronously, will the performance
go down?
 
My understanding is - I can't use threadpool, because FormA  loads FormB
and which inturn calls a method Asynchronously. FormA may load 100
FormB, but FormB will call the method only once per instance.
 
My additional questions are, 
a. I don't have a need to call endinvoke, What will happen to that child
thread, when it will die?
b. How do I control the child thread, i.e. terminate the child thread
created my the asycn call?
 
 
Thanks,
Venkat Sathiamurthy, PMP
 
Please see the below code:
 
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Threading;

namespace TestThreadHold

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.Button button1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//Thread.CurrentThread.Name ="Master";

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null) 

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#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 InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

// 

// button1

// 

this.button1.Location = new System.Drawing.Point(64, 80);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(112, 23);

this.button1.TabIndex = 0;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

// 

// Form1

// 

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

static void Main() 

{

Application.Run(new Form1());

}

private void button1_Click(object sender, System.EventArgs e)

{

Form2 frm2 = new Form2 ();

frm2.Show ();

}

private void Form1_Load(object sender, System.EventArgs e)

{

}

}

}

 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Threading;

namespace TestThreadHold

{

/// <summary>

/// Summary description for Form2.

/// </summary>

public class Form2 : System.Windows.Forms.Form

{

delegate void mydelegate();

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form2()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#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 InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.SuspendLayout();

// 

// button1

// 

this.button1.Location = new System.Drawing.Point(40, 24);

this.button1.Name = "button1";

this.button1.TabIndex = 0;

this.button1.Text = "button1";

// 

// button2

// 

this.button2.Location = new System.Drawing.Point(40, 64);

this.button2.Name = "button2";

this.button2.TabIndex = 1;

this.button2.Text = "button2";

// 

// Form2

// 

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Name = "Form2";

this.Text = "Form2";

this.Load += new System.EventHandler(this.Form2_Load);

this.ResumeLayout(false);

}

#endregion

private void button1_Click(object sender, System.EventArgs e)

{

MessageBox.Show ("Test1");

}

private void button2_Click(object sender, System.EventArgs e)

{

MessageBox.Show ("Test2");

}

private void Form2_Load(object sender, System.EventArgs e)

{

mydelegate dl=new mydelegate(Form2_EventSubscribe);

dl.BeginInvoke(null,null);

}

private void Form2_EventSubscribe()

{

//Thread.CurrentThread.Name ="Worker Thread" + DateTime.Now.ToString ();

Thread.Sleep (new TimeSpan (0,0,0,5,0));

if("NO CONNECTION"=="NO CONNECTION")

{

this.button1.Click += new System.EventHandler(this.button1_Click);

this.button2.Click += new System.EventHandler(this.button2_Click);

this.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.Form2_MouseDown);

}

else

{

this.button1.Click += new System.EventHandler(this.button1_Click);

this.button2.Click += new System.EventHandler(this.button2_Click);

MessageBox.Show ("Connection Succeed");

}

}

private void Form2_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)

{

this.Close ();

}

}

}

 

 

 

 

 

 

 
 
 

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to