TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Wallance Toh
NA
9
0
help with Threading with textboxes
Oct 7 2008 4:53 AM
hi, im new here.
i have a thread, with textboxes, i have invoker which invokes when it is required.
when it invokes, the text was able to show, but if it doesn't require invoke, i just wrote
textbox1.Text += "thestring";
but the textbox was unable to show, anyone know how to solve it?
my textbox code it's under a function, where my thread calls it.
public void updateit(string message)
{
if (txtrecieve.IsDisposed) return;
if (txtrecieve.InvokeRequired)
{
invoker = new GeneralDelegate(MethodRunningInMainThread);
txtrecieve.Invoke(invoker, new object[] { message });
}
else
{
txtrecieve.Text += message;
}
}
my thread
private void Listen()
{
Chat_Listen cl = new Chat_Listen(l2);
while (true)
{
myport = cl.returnport();
string message = cl.Listen(pass, salt, init);
string[] part = message.Split(';');
if (part[0] == "sendmsg2")
{
string username = part[2].ToString() + ":" + part[3].ToString();
string msgRecieve = " Says: " + part[1].ToString();
string message1 = username + msgRecieve;
updateit(message1);
}
}
}
the one that activates the thread
private void Chat_Load(object sender, EventArgs e)
{
if (!this.IsHandleCreated)
{
lock (this)
{
this.CreateHandle();
this.CreateControl();
this.CreateGraphics();
}
}
dp_local.Image = local;
//dp_remote.Image = remoteimg;
this.Text = "Talking to: " + remoteNickname;
Sender = new Thread(new ThreadStart(Send));
Listener = new Thread(new ThreadStart(Listen));
//Listener.IsBackground = true;
Listener.Start();
}
thanks.
Reply
Answers (
8
)
Performance enhancements make this C# application slower...any ideas what is going on?
Constructors