473,383 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

C# question about threads and GUI

14
Hi,
I have another question,
I try to make my threads updating the form,
it works fine, for the first thread ,
but afterwards its not updating the labels on the form anymore
not from inside the thread and not outside,
tried to use refresh() and DoEvents() , nothing worked out, is this function SetText lock the control or something ?



the code I use to do it , is a code I found on this site,
this is what it looks like:

delegate void SetTextCallback(string text);

private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.label6.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });

}
else
{
this.label6.Text = text;
}
}


public string Scan(string stat)
{
if (stat == "1")
{

//during this thread run labels are updated fine.
z = new Thread(delegate() { FileSearch("*.exe"); });
//Start the thread
z.Start();

}
if (stat == "2")
{
//at this point the labels are not updated anymore on the GUI,
// not in threads and not outside them.

label6.Text="testetstestsetsetse";
SetText("testing...........................");
Application.DoEvents();
//at the messagebox it is showing the new text and on the form it doesnt.
MessageBox.Show(label6.Text);
z = new Thread(delegate() { FileSearch("*.com"); });
z.Start();
}
Oct 30 '07 #1
0 1093

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nick Marden | last post by:
I am trying to use threads::shared to make a thread-safe object. It appears to be the case that copying a blessed-then-shared reference to another shared variable keeps the underlying structure...
5
by: Peter Kirk | last post by:
Hi, I see in the ThreadPool documentation that the pool has a default limit of 25 threads. Is it correctly understood that this limit is for my entire application? So if I have several...
2
by: Servé Lau | last post by:
I have been rewriting a C++ isapi into a C# asp.net application, but because it was my first one and created within a tight schedule I have some questions to make sure if I did it right. 1. Does...
3
by: Henri | last post by:
1) Do Shared methods always need to be synchronised to be thread-safe? 2) Why must SyncLock be used with a reference type? I can't get the relation between threads and a type. Thanks for your...
6
by: Roka | last post by:
Hi all. I'm reading a program which used the sentence below: #define NUM_THREADS 10 ... ... int rand_num; rand_num = 1+ (int) (9.0 * rand() / (RAND_MAX + 1.0)); sleep(rand_num); ... ......
3
by: michdoh | last post by:
Hi All I'm looking for some help on creating a basic multi threaded application. i'n new to threads in this environment so for test purposes I've produced a very basic program. (which doesn't...
7
by: Diego F. | last post by:
Hello. I have a doubt about multi-threading, if it is or not the best way to achieve the following: I have a server application that listens a port through a socket. A client will send messages...
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
5
by: FP | last post by:
Hi, i'm currently developing a class to communicate with a serial device,using the SerialPort component. Basically,the main application will interact with this class through its method "Call",the...
19
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.