Click here to Skip to main content
16,004,887 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGrid, 2 (easy) Questions Pin
DougW4826-Mar-04 6:55
DougW4826-Mar-04 6:55 
GeneralRe: DataGrid, 2 (easy) Questions Pin
Charlie Williams26-Mar-04 7:16
Charlie Williams26-Mar-04 7:16 
GeneralRe: DataGrid, 2 (easy) Questions Pin
partyganger26-Mar-04 9:54
partyganger26-Mar-04 9:54 
GeneralCommunicating with a Thread Pin
Demian Panello26-Mar-04 4:24
Demian Panello26-Mar-04 4:24 
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 4:51
sponsorJudah Gabriel Himango26-Mar-04 4:51 
GeneralRe: Communicating with a Thread Pin
SapiensBwG26-Mar-04 5:00
SapiensBwG26-Mar-04 5:00 
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 5:05
sponsorJudah Gabriel Himango26-Mar-04 5:05 
GeneralRe: Communicating with a Thread Pin
Heath Stewart26-Mar-04 4:58
protectorHeath Stewart26-Mar-04 4:58 
Use Control.InvokeRequired and Control.Invoke from threads other than the thread on which the control was created. Global variables are also not a very good way unless you use good locking when reading/writing from/to them (the lock keyword in C# is a simple way to do this using a monitor). To use a global variable, you can always use a static property or, if your threaded method is a method defined on the Control class that contains your TextBox, just use a private variable (and be sure to lock it).

To write to the text box, make sure your thread class or procedure has a reference to your TextBox (for example, you could thread a single method in your class which contains the TextBox reference). If you're not sure if your method would be threaded or not, use the code below (otherwise eliminate the check for Control.InvokeRequired):
private void ReadFromPort()
{
  string value = value from port;
  if (text1.InvokeRequired)
  {
    // This isn't really optimized, but it's only an example...
    Type t = text1.GetType();
    MethodInfo info = t.GetProperty("Text").GetSetMethod();
    Delegate d = Delegate.CreateDelegate(t, info);
    text1.Invoke(d, new object[] {value});
  }
  else text1.Text = value;
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 5:24
sponsorJudah Gabriel Himango26-Mar-04 5:24 
GeneralRe: Communicating with a Thread Pin
SapiensBwG26-Mar-04 5:44
SapiensBwG26-Mar-04 5:44 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 6:45
Demian Panello26-Mar-04 6:45 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 7:21
Demian Panello26-Mar-04 7:21 
GeneralRe: Communicating with a Thread Pin
Heath Stewart26-Mar-04 7:41
protectorHeath Stewart26-Mar-04 7:41 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 8:21
Demian Panello26-Mar-04 8:21 
GeneralRe: Communicating with a Thread Pin
Heath Stewart26-Mar-04 8:30
protectorHeath Stewart26-Mar-04 8:30 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 9:11
Demian Panello26-Mar-04 9:11 
GeneralFlickering :( Pin
bouli26-Mar-04 3:44
bouli26-Mar-04 3:44 
GeneralRe: Flickering :( Pin
Judah Gabriel Himango26-Mar-04 3:52
sponsorJudah Gabriel Himango26-Mar-04 3:52 
GeneralRe: Flickering :( Pin
bouli26-Mar-04 4:36
bouli26-Mar-04 4:36 
GeneralRe: Flickering :( Pin
Heath Stewart26-Mar-04 4:29
protectorHeath Stewart26-Mar-04 4:29 
GeneralRe: Flickering :( Pin
bouli26-Mar-04 4:35
bouli26-Mar-04 4:35 
GeneralRe: Flickering :( Pin
Heath Stewart26-Mar-04 4:46
protectorHeath Stewart26-Mar-04 4:46 
GeneralRe: Flickering :( Pin
bouli26-Mar-04 5:14
bouli26-Mar-04 5:14 
GeneralRe: Flickering :( Pin
bouli26-Mar-04 5:22
bouli26-Mar-04 5:22 
GeneralRe: Flickering :( Pin
Heath Stewart26-Mar-04 7:38
protectorHeath Stewart26-Mar-04 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.