DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 23 Jul 2007 06:03:44 -0700,    posted on: microsoft.public.dotnet.framework.compactframework        back       

Thread Index
  1    hassanmushtaq
          2    dbgrick
          3    unknown
          4    hassanmushtaq
                 5    ctacke/ ctacke[at]opennetcf[dot]com
          6    hassanmushtaq
          7    Jeff Newman


Control.Invoke in CF 1.0   
hi
i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
control from any other thread. i see alot of examples from web but it
rather always gives exceptions Argument exception. now my code didn't
give any exception but it is not working as i code to.

i have a form having a list box and button on it.

public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.MainMenu mainMenu1;
		private Thread t;


		public Form1()
		{
			//
			// 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 )
		{
			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.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.button1 = new System.Windows.Forms.Button();
			//
			// listBox1
			//
			this.listBox1.Location = new System.Drawing.Point(56, 24);
			this.listBox1.Size = new System.Drawing.Size(100, 114);
			//
			// button1
			//
			this.button1.Location = new System.Drawing.Point(72, 168);
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			//
			// Form1
			//
			this.Controls.Add(this.button1);
			this.Controls.Add(this.listBox1);
			this.Menu = this.mainMenu1;
			this.Text = "Form1";

		}
		#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)
		{
			cThread tt = new cThread();
			tt.th = this.t;
			t = new Thread(new ThreadStart(tt.Starts));
			t.Start();
		}
		//public delegate void InsertintoList(object sender,
System.EventArgs e);

		public void InsertList()
		{
			this.listBox1.Invoke(new EventHandler(this.Inserting));
		}
		protected void Inserting(object sender, System.EventArgs e)
		{
			this.listBox1.Items.Add("hassan");
			//MessageBox.Show(this.listBox1.ToString());
		}
	}

and i have a class named cThread

using System;
using System.Data;
using System.Windows.Forms;
using System.Threading;

namespace TestingInvoke
{
	/// <summary>
	/// Summary description for cThread.
	/// </summary>
	public class cThread
	{
		public Thread th;
		private bool   stop;
		public cThread()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public void Starts()
		{
			int i=0;
			try
			{
				while(true)
				{
					Thread.Sleep(100);
					new Form1().InsertList();
					if(stop){break;}
					i++;
					if(i > 5) { this.Stop();}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}
		}

		public void Stop()
		{
			this.stop=true;
		}
	}
}

in that cThread class i want to insert item in list. it was not doing
anything neither give me exception nor inserting the items.
plz help me
hassan mushtaq
Date:Mon, 23 Jul 2007 06:03:44 -0700   Author:  

RE: Control.Invoke in CF 1.0   
Try calling Application.DoEvents in the InsertList method.

Rick D.
Contractor

"hassanmushtaq" wrote:


> hi
> i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
> control from any other thread. i see alot of examples from web but it
> rather always gives exceptions Argument exception. now my code didn't
> give any exception but it is not working as i code to.
> 
> i have a form having a list box and button on it.
> 
> public class Form1 : System.Windows.Forms.Form
> 	{
> 		private System.Windows.Forms.ListBox listBox1;
> 		private System.Windows.Forms.Button button1;
> 		private System.Windows.Forms.MainMenu mainMenu1;
> 		private Thread t;
> 
> 
> 		public Form1()
> 		{
> 			//
> 			// 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 )
> 		{
> 			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.mainMenu1 = new System.Windows.Forms.MainMenu();
> 			this.listBox1 = new System.Windows.Forms.ListBox();
> 			this.button1 = new System.Windows.Forms.Button();
> 			//
> 			// listBox1
> 			//
> 			this.listBox1.Location = new System.Drawing.Point(56, 24);
> 			this.listBox1.Size = new System.Drawing.Size(100, 114);
> 			//
> 			// button1
> 			//
> 			this.button1.Location = new System.Drawing.Point(72, 168);
> 			this.button1.Text = "button1";
> 			this.button1.Click += new System.EventHandler(this.button1_Click);
> 			//
> 			// Form1
> 			//
> 			this.Controls.Add(this.button1);
> 			this.Controls.Add(this.listBox1);
> 			this.Menu = this.mainMenu1;
> 			this.Text = "Form1";
> 
> 		}
> 		#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)
> 		{
> 			cThread tt = new cThread();
> 			tt.th = this.t;
> 			t = new Thread(new ThreadStart(tt.Starts));
> 			t.Start();
> 		}
> 		//public delegate void InsertintoList(object sender,
> System.EventArgs e);
> 
> 		public void InsertList()
> 		{
> 			this.listBox1.Invoke(new EventHandler(this.Inserting));
> 		}
> 		protected void Inserting(object sender, System.EventArgs e)
> 		{
> 			this.listBox1.Items.Add("hassan");
> 			//MessageBox.Show(this.listBox1.ToString());
> 		}
> 	}
> 
> and i have a class named cThread
> 
> using System;
> using System.Data;
> using System.Windows.Forms;
> using System.Threading;
> 
> namespace TestingInvoke
> {
> 	/// <summary>
> 	/// Summary description for cThread.
> 	/// </summary>
> 	public class cThread
> 	{
> 		public Thread th;
> 		private bool   stop;
> 		public cThread()
> 		{
> 			//
> 			// TODO: Add constructor logic here
> 			//
> 		}
> 
> 		public void Starts()
> 		{
> 			int i=0;
> 			try
> 			{
> 				while(true)
> 				{
> 					Thread.Sleep(100);
> 					new Form1().InsertList();
> 					if(stop){break;}
> 					i++;
> 					if(i > 5) { this.Stop();}
> 				}
> 			}
> 			catch(Exception ex)
> 			{
> 				MessageBox.Show(ex.ToString());
> 			}
> 		}
> 
> 		public void Stop()
> 		{
> 			this.stop=true;
> 		}
> 	}
> }
> 
> in that cThread class i want to insert item in list. it was not doing
> anything neither give me exception nor inserting the items.
> plz help me
> hassan mushtaq
> 
> 
Date:Mon, 23 Jul 2007 09:24:03 -0700   Author:  

Re: Control.Invoke in CF 1.0   
On Jul 23, 9:03 am, hassanmushtaq  wrote:

> hi
> i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
> control from any other thread. i see alot of examples from web but it
> rather always gives exceptions Argument exception. now my code didn't
> give any exception but it is not working as i code to.
>
> i have a form having a list box and button on it.
>
> public class Form1 : System.Windows.Forms.Form
>         {
>                 private System.Windows.Forms.ListBox listBox1;
>                 private System.Windows.Forms.Button button1;
>                 private System.Windows.Forms.MainMenu mainMenu1;
>                 private Thread t;
>
>                 public Form1()
>                 {
>                         //
>                         // 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 )
>                 {
>                         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.mainMenu1 = new System.Windows.Forms.MainMenu();
>                         this.listBox1 = new System.Windows.Forms.ListBox();
>                         this.button1 = new System.Windows.Forms.Button();
>                         //
>                         // listBox1
>                         //
>                         this.listBox1.Location = new System.Drawing.Point(56, 24);
>                         this.listBox1.Size = new System.Drawing.Size(100, 114);
>                         //
>                         // button1
>                         //
>                         this.button1.Location = new System.Drawing.Point(72, 168);
>                         this.button1.Text = "button1";
>                         this.button1.Click += new System.EventHandler(this.button1_Click);
>                         //
>                         // Form1
>                         //
>                         this.Controls.Add(this.button1);
>                         this.Controls.Add(this.listBox1);
>                         this.Menu = this.mainMenu1;
>                         this.Text = "Form1";
>
>                 }
>                 #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)
>                 {
>                         cThread tt = new cThread();
>                         tt.th = this.t;
>                         t = new Thread(new ThreadStart(tt.Starts));
>                         t.Start();
>                 }
>                 //public delegate void InsertintoList(object sender,
> System.EventArgs e);
>
>                 public void InsertList()
>                 {
>                         this.listBox1.Invoke(new EventHandler(this.Inserting));
>                 }
>                 protected void Inserting(object sender, System.EventArgs e)
>                 {
>                         this.listBox1.Items.Add("hassan");
>                         //MessageBox.Show(this.listBox1.ToString());
>                 }
>         }
>
> and i have a class named cThread
>
> using System;
> using System.Data;
> using System.Windows.Forms;
> using System.Threading;
>
> namespace TestingInvoke
> {
>         /// <summary>
>         /// Summary description for cThread.
>         /// </summary>
>         public class cThread
>         {
>                 public Thread th;
>                 private bool   stop;
>                 public cThread()
>                 {
>                         //
>                         // TODO: Add constructor logic here
>                         //
>                 }
>
>                 public void Starts()
>                 {
>                         int i=0;
>                         try
>                         {
>                                 while(true)
>                                 {
>                                         Thread.Sleep(100);
>                                         new Form1().InsertList();
>                                         if(stop){break;}
>                                         i++;
>                                         if(i > 5) { this.Stop();}
>                                 }
>                         }
>                         catch(Exception ex)
>                         {
>                                 MessageBox.Show(ex.ToString());
>                         }
>                 }
>
>                 public void Stop()
>                 {
>                         this.stop=true;
>                 }
>         }
>
> }
>
> in that cThread class i want to insert item in list. it was not doing
> anything neither give me exception nor inserting the items.
> plz help me
> hassan mushtaq



The form that is being displayed in your program is created in the
line

Application.Run(new Form1());

You then create another form with

new Form1().InsertList();

InsertList() has to be called on the form that is in
Application.Run().
Date:Mon, 23 Jul 2007 18:13:16 -0000   Author:  

Re: Control.Invoke in CF 1.0   
On Jul 23, 11:13 pm, "Jeffrey.M.New...@gmail.com"
 wrote:

> On Jul 23, 9:03 am, hassanmushtaq  wrote:
>
>
>
>
>
> > hi
> > i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
> > control from any other thread. i see alot of examples from web but it
> > rather always gives exceptions Argument exception. now my code didn't
> > give any exception but it is not working as i code to.
>
> > i have a form having a list box and button on it.
>
> > public class Form1 : System.Windows.Forms.Form
> >         {
> >                 private System.Windows.Forms.ListBox listBox1;
> >                 private System.Windows.Forms.Button button1;
> >                 private System.Windows.Forms.MainMenu mainMenu1;
> >                 private Thread t;
>
> >                 public Form1()
> >                 {
> >                         //
> >                         // 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 )
> >                 {
> >                         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.mainMenu1 = new System.Windows.Forms.MainMenu();
> >                         this.listBox1 = new System.Windows.Forms.ListBox();
> >                         this.button1 = new System.Windows.Forms.Button();
> >                         //
> >                         // listBox1
> >                         //
> >                         this.listBox1.Location = new System.Drawing.Point(56, 24);
> >                         this.listBox1.Size = new System.Drawing.Size(100, 114);
> >                         //
> >                         // button1
> >                         //
> >                         this.button1.Location = new System.Drawing.Point(72, 168);
> >                         this.button1.Text = "button1";
> >                         this.button1.Click += new System.EventHandler(this.button1_Click);
> >                         //
> >                         // Form1
> >                         //
> >                         this.Controls.Add(this.button1);
> >                         this.Controls.Add(this.listBox1);
> >                         this.Menu = this.mainMenu1;
> >                         this.Text = "Form1";
>
> >                 }
> >                 #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)
> >                 {
> >                         cThread tt = new cThread();
> >                         tt.th = this.t;
> >                         t = new Thread(new ThreadStart(tt.Starts));
> >                         t.Start();
> >                 }
> >                 //public delegate void InsertintoList(object sender,
> > System.EventArgs e);
>
> >                 public void InsertList()
> >                 {
> >                         this.listBox1.Invoke(new EventHandler(this.Inserting));
> >                 }
> >                 protected void Inserting(object sender, System.EventArgs e)
> >                 {
> >                         this.listBox1.Items.Add("hassan");
> >                         //MessageBox.Show(this.listBox1.ToString());
> >                 }
> >         }
>
> > and i have a class named cThread
>
> > using System;
> > using System.Data;
> > using System.Windows.Forms;
> > using System.Threading;
>
> > namespace TestingInvoke
> > {
> >         /// <summary>
> >         /// Summary description for cThread.
> >         /// </summary>
> >         public class cThread
> >         {
> >                 public Thread th;
> >                 private bool   stop;
> >                 public cThread()
> >                 {
> >                         //
> >                         // TODO: Add constructor logic here
> >                         //
> >                 }
>
> >                 public void Starts()
> >                 {
> >                         int i=0;
> >                         try
> >                         {
> >                                 while(true)
> >                                 {
> >                                         Thread.Sleep(100);
> >                                         new Form1().InsertList();
> >                                         if(stop){break;}
> >                                         i++;
> >                                         if(i > 5) { this.Stop();}
> >                                 }
> >                         }
> >                         catch(Exception ex)
> >                         {
> >                                 MessageBox.Show(ex.ToString());
> >                         }
> >                 }
>
> >                 public void Stop()
> >                 {
> >                         this.stop=true;
> >                 }
> >         }
>
> > }
>
> > in that cThread class i want to insert item in list. it was not doing
> > anything neither give me exception nor inserting the items.
> > plz help me
> > hassan mushtaq
>
> The form that is being displayed in your program is created in the
> line
>
> Application.Run(new Form1());
>
> You then create another form with
>
> new Form1().InsertList();
>
> InsertList() has to be called on the form that is in
> Application.Run().- Hide quoted text -
>
> - Show quoted text -


hi,
i could understand how can call InsertList() method in my Form class.
i have to insert item in listbox from the thread class.
so plz give me solution
regardz
hassan mushtaq
Date:Tue, 24 Jul 2007 01:13:01 -0700   Author:  

Re: Control.Invoke in CF 1.0   
Jeffrey gave you the solution.  Don't create a new Form1 when you want to 
add items to the list.  Use the original instance.


-- 

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com


"hassanmushtaq"  wrote in message 
news:1185264781.505322.120870@57g2000hsv.googlegroups.com...

> On Jul 23, 11:13 pm, "Jeffrey.M.New...@gmail.com"
>  wrote:
>> On Jul 23, 9:03 am, hassanmushtaq  wrote:
>>
>>
>>
>>
>>
>> > hi
>> > i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
>> > control from any other thread. i see alot of examples from web but it
>> > rather always gives exceptions Argument exception. now my code didn't
>> > give any exception but it is not working as i code to.
>>
>> > i have a form having a list box and button on it.
>>
>> > public class Form1 : System.Windows.Forms.Form
>> >         {
>> >                 private System.Windows.Forms.ListBox listBox1;
>> >                 private System.Windows.Forms.Button button1;
>> >                 private System.Windows.Forms.MainMenu mainMenu1;
>> >                 private Thread t;
>>
>> >                 public Form1()
>> >                 {
>> >                         //
>> >                         // 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 )
>> >                 {
>> >                         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.mainMenu1 = new 
>> > System.Windows.Forms.MainMenu();
>> >                         this.listBox1 = new 
>> > System.Windows.Forms.ListBox();
>> >                         this.button1 = new 
>> > System.Windows.Forms.Button();
>> >                         //
>> >                         // listBox1
>> >                         //
>> >                         this.listBox1.Location = new 
>> > System.Drawing.Point(56, 24);
>> >                         this.listBox1.Size = new 
>> > System.Drawing.Size(100, 114);
>> >                         //
>> >                         // button1
>> >                         //
>> >                         this.button1.Location = new 
>> > System.Drawing.Point(72, 168);
>> >                         this.button1.Text = "button1";
>> >                         this.button1.Click += new 
>> > System.EventHandler(this.button1_Click);
>> >                         //
>> >                         // Form1
>> >                         //
>> >                         this.Controls.Add(this.button1);
>> >                         this.Controls.Add(this.listBox1);
>> >                         this.Menu = this.mainMenu1;
>> >                         this.Text = "Form1";
>>
>> >                 }
>> >                 #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)
>> >                 {
>> >                         cThread tt = new cThread();
>> >                         tt.th = this.t;
>> >                         t = new Thread(new ThreadStart(tt.Starts));
>> >                         t.Start();
>> >                 }
>> >                 //public delegate void InsertintoList(object sender,
>> > System.EventArgs e);
>>
>> >                 public void InsertList()
>> >                 {
>> >                         this.listBox1.Invoke(new 
>> > EventHandler(this.Inserting));
>> >                 }
>> >                 protected void Inserting(object sender, 
>> > System.EventArgs e)
>> >                 {
>> >                         this.listBox1.Items.Add("hassan");
>> >                         //MessageBox.Show(this.listBox1.ToString());
>> >                 }
>> >         }
>>
>> > and i have a class named cThread
>>
>> > using System;
>> > using System.Data;
>> > using System.Windows.Forms;
>> > using System.Threading;
>>
>> > namespace TestingInvoke
>> > {
>> >         /// <summary>
>> >         /// Summary description for cThread.
>> >         /// </summary>
>> >         public class cThread
>> >         {
>> >                 public Thread th;
>> >                 private bool   stop;
>> >                 public cThread()
>> >                 {
>> >                         //
>> >                         // TODO: Add constructor logic here
>> >                         //
>> >                 }
>>
>> >                 public void Starts()
>> >                 {
>> >                         int i=0;
>> >                         try
>> >                         {
>> >                                 while(true)
>> >                                 {
>> >                                         Thread.Sleep(100);
>> >                                         new Form1().InsertList();
>> >                                         if(stop){break;}
>> >                                         i++;
>> >                                         if(i > 5) { this.Stop();}
>> >                                 }
>> >                         }
>> >                         catch(Exception ex)
>> >                         {
>> >                                 MessageBox.Show(ex.ToString());
>> >                         }
>> >                 }
>>
>> >                 public void Stop()
>> >                 {
>> >                         this.stop=true;
>> >                 }
>> >         }
>>
>> > }
>>
>> > in that cThread class i want to insert item in list. it was not doing
>> > anything neither give me exception nor inserting the items.
>> > plz help me
>> > hassan mushtaq
>>
>> The form that is being displayed in your program is created in the
>> line
>>
>> Application.Run(new Form1());
>>
>> You then create another form with
>>
>> new Form1().InsertList();
>>
>> InsertList() has to be called on the form that is in
>> Application.Run().- Hide quoted text -
>>
>> - Show quoted text -
>
> hi,
> i could understand how can call InsertList() method in my Form class.
> i have to insert item in listbox from the thread class.
> so plz give me solution
> regardz
> hassan mushtaq
> 
Date:Tue, 24 Jul 2007 10:57:14 -0500   Author:  

Re: Control.Invoke in CF 1.0   
On Jul 24, 8:57 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:

> Jeffrey gave you the solution.  Don't create a new Form1 when you want to
> add items to the list.  Use the original instance.
>
> --
>
> Chris Tacke, Embedded MVP
> OpenNETCF Consulting
> Managed Code in an Embedded Worldwww.OpenNETCF.com
>
> "hassanmushtaq"  wrote in message
>
> news:1185264781.505322.120870@57g2000hsv.googlegroups.com...
>
>
>
> > On Jul 23, 11:13 pm, "Jeffrey.M.New...@gmail.com"
> >  wrote:
> >> On Jul 23, 9:03 am, hassanmushtaq  wrote:
>
> >> > hi
> >> > i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
> >> > control from any other thread. i see alot of examples from web but it
> >> > rather always gives exceptions Argument exception. now my code didn't
> >> > give any exception but it is not working as i code to.
>
> >> > i have a form having a list box and button on it.
>
> >> > public class Form1 : System.Windows.Forms.Form
> >> >         {
> >> >                 private System.Windows.Forms.ListBox listBox1;
> >> >                 private System.Windows.Forms.Button button1;
> >> >                 private System.Windows.Forms.MainMenu mainMenu1;
> >> >                 private Thread t;
>
> >> >                 public Form1()
> >> >                 {
> >> >                         //
> >> >                         // 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 )
> >> >                 {
> >> >                         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.mainMenu1 = new
> >> > System.Windows.Forms.MainMenu();
> >> >                         this.listBox1 = new
> >> > System.Windows.Forms.ListBox();
> >> >                         this.button1 = new
> >> > System.Windows.Forms.Button();
> >> >                         //
> >> >                         // listBox1
> >> >                         //
> >> >                         this.listBox1.Location = new
> >> > System.Drawing.Point(56, 24);
> >> >                         this.listBox1.Size = new
> >> > System.Drawing.Size(100, 114);
> >> >                         //
> >> >                         // button1
> >> >                         //
> >> >                         this.button1.Location = new
> >> > System.Drawing.Point(72, 168);
> >> >                         this.button1.Text = "button1";
> >> >                         this.button1.Click += new
> >> > System.EventHandler(this.button1_Click);
> >> >                         //
> >> >                         // Form1
> >> >                         //
> >> >                         this.Controls.Add(this.button1);
> >> >                         this.Controls.Add(this.listBox1);
> >> >                         this.Menu = this.mainMenu1;
> >> >                         this.Text = "Form1";
>
> >> >                 }
> >> >                 #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)
> >> >                 {
> >> >                         cThread tt = new cThread();
> >> >                         tt.th = this.t;
> >> >                         t = new Thread(new ThreadStart(tt.Starts));
> >> >                         t.Start();
> >> >                 }
> >> >                 //public delegate void InsertintoList(object sender,
> >> > System.EventArgs e);
>
> >> >                 public void InsertList()
> >> >                 {
> >> >                         this.listBox1.Invoke(new
> >> > EventHandler(this.Inserting));
> >> >                 }
> >> >                 protected void Inserting(object sender,
> >> > System.EventArgs e)
> >> >                 {
> >> >                         this.listBox1.Items.Add("hassan");
> >> >                         //MessageBox.Show(this.listBox1.ToString());
> >> >                 }
> >> >         }
>
> >> > and i have a class named cThread
>
> >> > using System;
> >> > using System.Data;
> >> > using System.Windows.Forms;
> >> > using System.Threading;
>
> >> > namespace TestingInvoke
> >> > {
> >> >         /// <summary>
> >> >         /// Summary description for cThread.
> >> >         /// </summary>
> >> >         public class cThread
> >> >         {
> >> >                 public Thread th;
> >> >                 private bool   stop;
> >> >                 public cThread()
> >> >                 {
> >> >                         //
> >> >                         // TODO: Add constructor logic here
> >> >                         //
> >> >                 }
>
> >> >                 public void Starts()
> >> >                 {
> >> >                         int i=0;
> >> >                         try
> >> >                         {
> >> >                                 while(true)
> >> >                                 {
> >> >                                         Thread.Sleep(100);
> >> >                                         new Form1().InsertList();
> >> >                                         if(stop){break;}
> >> >                                         i++;
> >> >                                         if(i > 5) { this.Stop();}
> >> >                                 }
> >> >                         }
> >> >                         catch(Exception ex)
> >> >                         {
> >> >                                 MessageBox.Show(ex.ToString());
> >> >                         }
> >> >                 }
>
> >> >                 public void Stop()
> >> >                 {
> >> >                         this.stop=true;
> >> >                 }
> >> >         }
>
> >> > }
>
> >> > in that cThread class i want to insert item in list. it was not doing
> >> > anything neither give me exception nor inserting the items.
> >> > plz help me
> >> > hassan mushtaq
>
> >> The form that is being displayed in your program is created in the
> >> line
>
> >> Application.Run(new Form1());
>
> >> You then create another form with
>
> >> new Form1().InsertList();
>
> >> InsertList() has to be called on the form that is in
> >> Application.Run().- Hide quoted text -
>
> >> - Show quoted text -
>
> > hi,
> > i could understand how can call InsertList() method in my Form class.
> > i have to insert item in listbox from the thread class.
> > so plz give me solution
> > regardz
> > hassan mushtaq- Hide quoted text -
>
> - Show quoted text -


thnx for response. u reply me that not to create a new instance of
Form1. then hoe can i access that funtion in form1 class. either i
make it static function that i called it from class name. or what any
suggestion
regardz
hassan mushtaq
Date:Wed, 25 Jul 2007 00:51:33 -0700   Author:  

Re: Control.Invoke in CF 1.0   
On Jul 25, 3:51 am, hassanmushtaq  wrote:

> On Jul 24, 8:57 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
>
>
>
> > Jeffrey gave you the solution.  Don't create a new Form1 when you want to
> > add items to the list.  Use the original instance.
>
> > --
>
> > Chris Tacke, Embedded MVP
> > OpenNETCF Consulting
> > Managed Code in an Embedded Worldwww.OpenNETCF.com
>
> > "hassanmushtaq"  wrote in message
>
> >news:1185264781.505322.120870@57g2000hsv.googlegroups.com...
>
> > > On Jul 23, 11:13 pm, "Jeffrey.M.New...@gmail.com"
> > >  wrote:
> > >> On Jul 23, 9:03 am, hassanmushtaq  wrote:
>
> > >> > hi
> > >> > i m using VS 2003 (C#) CF 1.0. i have a problem while accessing any
> > >> > control from any other thread. i see alot of examples from web but it
> > >> > rather always gives exceptions Argument exception. now my code didn't
> > >> > give any exception but it is not working as i code to.
>
> > >> > i have a form having a list box and button on it.
>
> > >> > public class Form1 : System.Windows.Forms.Form
> > >> >         {
> > >> >                 private System.Windows.Forms.ListBox listBox1;
> > >> >                 private System.Windows.Forms.Button button1;
> > >> >                 private System.Windows.Forms.MainMenu mainMenu1;
> > >> >                 private Thread t;
>
> > >> >                 public Form1()
> > >> >                 {
> > >> >                         //
> > >> >                         // 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 )
> > >> >                 {
> > >> >                         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.mainMenu1 = new
> > >> > System.Windows.Forms.MainMenu();
> > >> >                         this.listBox1 = new
> > >> > System.Windows.Forms.ListBox();
> > >> >                         this.button1 = new
> > >> > System.Windows.Forms.Button();
> > >> >                         //
> > >> >                         // listBox1
> > >> >                         //
> > >> >                         this.listBox1.Location = new
> > >> > System.Drawing.Point(56, 24);
> > >> >                         this.listBox1.Size = new
> > >> > System.Drawing.Size(100, 114);
> > >> >                         //
> > >> >                         // button1
> > >> >                         //
> > >> >                         this.button1.Location = new
> > >> > System.Drawing.Point(72, 168);
> > >> >                         this.button1.Text = "button1";
> > >> >                         this.button1.Click += new
> > >> > System.EventHandler(this.button1_Click);
> > >> >                         //
> > >> >                         // Form1
> > >> >                         //
> > >> >                         this.Controls.Add(this.button1);
> > >> >                         this.Controls.Add(this.listBox1);
> > >> >                         this.Menu = this.mainMenu1;
> > >> >                         this.Text = "Form1";
>
> > >> >                 }
> > >> >                 #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)
> > >> >                 {
> > >> >                         cThread tt = new cThread();
> > >> >                         tt.th = this.t;
> > >> >                         t = new Thread(new ThreadStart(tt.Starts));
> > >> >                         t.Start();
> > >> >                 }
> > >> >                 //public delegate void InsertintoList(object sender,
> > >> > System.EventArgs e);
>
> > >> >                 public void InsertList()
> > >> >                 {
> > >> >                         this.listBox1.Invoke(new
> > >> > EventHandler(this.Inserting));
> > >> >                 }
> > >> >                 protected void Inserting(object sender,
> > >> > System.EventArgs e)
> > >> >                 {
> > >> >                         this.listBox1.Items.Add("hassan");
> > >> >                         //MessageBox.Show(this.listBox1.ToString());
> > >> >                 }
> > >> >         }
>
> > >> > and i have a class named cThread
>
> > >> > using System;
> > >> > using System.Data;
> > >> > using System.Windows.Forms;
> > >> > using System.Threading;
>
> > >> > namespace TestingInvoke
> > >> > {
> > >> >         /// <summary>
> > >> >         /// Summary description for cThread.
> > >> >         /// </summary>
> > >> >         public class cThread
> > >> >         {
> > >> >                 public Thread th;
> > >> >                 private bool   stop;
> > >> >                 public cThread()
> > >> >                 {
> > >> >                         //
> > >> >                         // TODO: Add constructor logic here
> > >> >                         //
> > >> >                 }
>
> > >> >                 public void Starts()
> > >> >                 {
> > >> >                         int i=0;
> > >> >                         try
> > >> >                         {
> > >> >                                 while(true)
> > >> >                                 {
> > >> >                                         Thread.Sleep(100);
> > >> >                                         new Form1().InsertList();
> > >> >                                         if(stop){break;}
> > >> >                                         i++;
> > >> >                                         if(i > 5) { this.Stop();}
> > >> >                                 }
> > >> >                         }
> > >> >                         catch(Exception ex)
> > >> >                         {
> > >> >                                 MessageBox.Show(ex.ToString());
> > >> >                         }
> > >> >                 }
>
> > >> >                 public void Stop()
> > >> >                 {
> > >> >                         this.stop=true;
> > >> >                 }
> > >> >         }
>
> > >> > }
>
> > >> > in that cThread class i want to insert item in list. it was not doing
> > >> > anything neither give me exception nor inserting the items.
> > >> > plz help me
> > >> > hassan mushtaq
>
> > >> The form that is being displayed in your program is created in the
> > >> line
>
> > >> Application.Run(new Form1());
>
> > >> You then create another form with
>
> > >> new Form1().InsertList();
>
> > >> InsertList() has to be called on the form that is in
> > >> Application.Run().- Hide quoted text -
>
> > >> - Show quoted text -
>
> > > hi,
> > > i could understand how can call InsertList() method in my Form class.
> > > i have to insert item in listbox from the thread class.
> > > so plz give me solution
> > > regardz
> > > hassan mushtaq- Hide quoted text -
>
> > - Show quoted text -
>
> thnx for response. u reply me that not to create a new instance of
> Form1. then hoe can i access that funtion in form1 class. either i
> make it static function that i called it from class name. or what any
> suggestion
> regardz
> hassan mushtaq


There are plenty of different ways to do this.  Try changing the
constructor of cThread to take in a reference to a form, then create
the thread as

cThread tt = new cThread(this);

Store the form in the thread, and use it as needed.
Date:Wed, 25 Jul 2007 14:24:37 -0000   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us